最新回答 / 慕斯卡8373086
def sums (n): refult = 0 if n > 0 and n <= 100: while n > 0 : refult = refult + n n -= 1 return refult else: return '参数要在1-100之间'n1 = 99print(sums(n1))def fact(n): if n == 1: return 1 ...
2021-03-20
a='python'
print('hello',a and 'world') #==>hello, python
在and语句下,a值为true,所以运算结果取决于前者
b=''
print('hello',b or 'world') #==>hello, world
在or语句下,b值为false(空,0,None),所以运算结果取后者
print('hello',a and 'world') #==>hello, python
在and语句下,a值为true,所以运算结果取决于前者
b=''
print('hello',b or 'world') #==>hello, world
在or语句下,b值为false(空,0,None),所以运算结果取后者
2021-03-20
搞那么复杂
def sub_sum(l):
j_sum=0
o_sum=0
for n in l:
if n%2 == 0 :
o_sum += n
else:
j_sum += n
return j_sum,o_sum
l=[1,3,5,2,4,6,7,8,9,10]
s=sub_sum(l)
print('奇数和={}'.format(s[0]))
print('偶数和={}'.format(s[1]))
def sub_sum(l):
j_sum=0
o_sum=0
for n in l:
if n%2 == 0 :
o_sum += n
else:
j_sum += n
return j_sum,o_sum
l=[1,3,5,2,4,6,7,8,9,10]
s=sub_sum(l)
print('奇数和={}'.format(s[0]))
print('偶数和={}'.format(s[1]))
2021-03-19
# Enter a code
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
S = set([1, 3, 5, 7, 9, 11])
for v1 in L:
if v1 in S:
S.remove(v1)
else:
S.add(v1)
print(S)
2021-03-19
names1= []
names2=['Jenny', 'Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
names1_set=set(names1)
#方法一
for v in names2:
names1_set.add(v)
print(names1_set)
#方法二
names1_set.update(names2)
print(names1_set)
names2=['Jenny', 'Ellena', 'Alice', 'Candy', 'David', 'Hally', 'Bob', 'Isen', 'Karl']
names1_set=set(names1)
#方法一
for v in names2:
names1_set.add(v)
print(names1_set)
#方法二
names1_set.update(names2)
print(names1_set)
2021-03-19
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
for x in s1:
if s1.isdisjoint(s2) == False:
print(x)
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
for x in s1:
if s1.isdisjoint(s2) == False:
print(x)
2021-03-19
最赞回答 / 幕布斯9526405
你直接吧print顶格就行了,Python语言里你这样写是表示print在while循环内,所以每循环一次就会执行一次,顶格之后就表示print在循环外,那循环结束之后才会执行一次print
2021-03-18
最新回答 / 幕布斯8123072
# Enter a code#coding=utf-8age = 19if age >= 18: print('adult') print('咚咚呛今年{}岁'.format(age))
2021-03-18
已采纳回答 / yunfan123
a=list(map(int,input().strip().split())) # 1 2 3 4 5 -1 -2 -3 -4 -5 c=list(filter(lambda x:x>=0,a)) b=list(filter(lambda x:x<0,a)) print(c,b)# output [1,2,3,4,5],[-1,-2,-3,-4,-5]
2021-03-17