我试图在Project Euler上用python弄湿我的脚,但是我遇到了第一个问题的问题(找到3或5的倍数之和到1000).我可以成功打印出三个和五个的倍数,但是当我尝试包含sum函数时,我得到以下错误:
TypeError:'int'对象不可迭代
任何帮助,将不胜感激.
n = 100
p = 0
while p<n:
p = p + 1
x = range(0, p)
# check to see if numbers are divisable by 3 or 5
def numcheck(x):
for numbers in x:
if numbers%3==0 and numbers%5==0:
sum(numbers)
numcheck(x)
Run Code Online (Sandbox Code Playgroud) python ×1