l=[1, 4, 5, 7, 9, 11]
def sub_sum(l):
suma=0
sumb=0
for a in l:
if a % 2 ==0:
suma=suma+a
else:
sumb=sumb+a
return suma,sumb
result=sub_sum(l)
print('偶数项和={}'.format(result[0]))
print('奇数项和={}'.format(result[1]))
def sub_sum(l):
suma=0
sumb=0
for a in l:
if a % 2 ==0:
suma=suma+a
else:
sumb=sumb+a
return suma,sumb
result=sub_sum(l)
print('偶数项和={}'.format(result[0]))
print('奇数项和={}'.format(result[1]))
2021-12-08
abc = 'Life is short,{}'
youneedPython = 'you need Python'
result = abc.format(youneedPython)
print(result)
youneedPython = 'you need Python'
result = abc.format(youneedPython)
print(result)
2021-12-08
已采纳回答 / weixin_慕前端4435978
因为第一行 template = 'Hello {w}, Hello {c}, Hello {b}, Hello {i}.' 里面的w,c,b,i是给该模板位置的代号名称,而不能作为一个变量,为了不重复,建议将下面赋值语句的变量名进行修改,如s1 = 'World's2 = 'China's3 = 'Beijing's4 = 'imooc'然后最后赋值给模块中的位置result = template.format(w=s1,c=s2,b=s3,i=s4)最后要记得打印出来print(result)💪
2021-12-07
x=[1,2,5,6,8]
def square_of_sum(x):
result=0
l=[]
for num in x:
result=num*num
l.append(result)
result=sum(l)
return result
m=square_of_sum(x)
print(m)
def square_of_sum(x):
result=0
l=[]
for num in x:
result=num*num
l.append(result)
result=sum(l)
return result
m=square_of_sum(x)
print(m)
2021-12-06
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if s1.isdisjoint(s2) != True:
for a in s1:
if a in s2:
print(a)
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
if s1.isdisjoint(s2) != True:
for a in s1:
if a in s2:
print(a)
2021-12-06
最新回答 / 慕圣8481703
cube[0]对应的是当前循环到的长方体list中的长,cube[1]是当前循环的长方体list中的宽,cube[2]是当前循环的长方体list中的高也可以这么理解。
2021-12-06
a = 0
i = 0
while True:
if a > 1000:
break
if a % 2 == 0:
i = i + a
a = a + 1
print(i)
i = 0
while True:
if a > 1000:
break
if a % 2 == 0:
i = i + a
a = a + 1
print(i)
2021-12-06
# Enter a code
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
s3=[]
for a in s1:
if a in s2:
s3.append(a)
else:
continue
print(s3)
s1 = set([1, 2, 3, 4, 5])
s2 = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
s3=[]
for a in s1:
if a in s2:
s3.append(a)
else:
continue
print(s3)
2021-12-06
age = 2
if age >= 18:
print('你是成年人,你{}岁了'.format(age))
print("adult")
elif age >= 6:
print('你是青少年,你{}岁了'.format(age))
print("teenager")
elif age >= 3:
print('你是小孩子,你{}岁了'.format(age))
print("kid")
else:
print('你是婴儿,你{}岁了'.format(age))
print("baby")
if age >= 18:
print('你是成年人,你{}岁了'.format(age))
print("adult")
elif age >= 6:
print('你是青少年,你{}岁了'.format(age))
print("teenager")
elif age >= 3:
print('你是小孩子,你{}岁了'.format(age))
print("kid")
else:
print('你是婴儿,你{}岁了'.format(age))
print("baby")
2021-12-05
age = 3
if age >= 18:
print("adult")
elif age >= 6:
print("teenager")
elif age >= 3:
print("kid")
else:
print("baby")
if age >= 18:
print("adult")
elif age >= 6:
print("teenager")
elif age >= 3:
print("kid")
else:
print("baby")
2021-12-05
age=11
if age>=18:
print('adult')
print('咚咚呛同学,你已成年')
else:
print('teenage')
print('咚咚呛同学,你未成年')
if age>=18:
print('adult')
print('咚咚呛同学,你已成年')
else:
print('teenage')
print('咚咚呛同学,你未成年')
2021-12-05