我可以用得到的偶数如下:将偶数添加到列表中?
numb=[1,2,3,4,5,6,7,8,9]
for i in numb:
if i%2!=0:
continue
print(i,end=',')
我的第一个问题是:我怎么能加入他们吗?即从列表中取出偶数并找出它们的总和? 我的第二个问题是:我可以从用户获取输入,并使用该添加它们:
sums=0
while True:
nums=input('Enter the numbers, leave blank to end :')
if nums=='':
break
else:
sums+=int(nums)
print('Their sum is',sums)
但如何把来自用户的输入,并把它们放在一起的列表,以便我可以只添加偶数号码?
所以这就是我错过了。 list_name.append –