我发现没有代码使用for循环来解决此问题。我的问题似乎是数字的加法
total = 0 #defined total
for number in range(1,101): #set a for loop with a range between (1-101)
if number %2 == 0: #if number(1-101) is divisible by 2 == 0
total = sum(int(number)) #TypeError: 'int' object is not iterable
print(total) # expected result is to print 2550
答案 0 :(得分:0)
您可以使用python内置函数sum
。
sum(range(0, 101, 2))