0
当我运行此代码来计算根2的渐近连分数:Python的 - 项目欧拉#57,理解错误
def root_two_expansion():
total=0
a=(3,2)
b=(7,5)
x=3
while x<=1000:
c=((sum(a)+sum(b)),sum(b))
if len(str(c[0]))>len(str(c[1])):
total+=1
a=b,b=c
x+=1
return total
print root_two_expansion()
我收到此错误:
069.506.py", line 7, in root_two_expansion c=((sum(a)+sum(b)),sum(b)) TypeError: 'int' object is not iterable
这是为什么?我不明白在哪个阶段代码试图迭代一个int。我会很感激任何建议。
在未来,你应该例如使用调试器在PyCharm帮助你弄清楚这种事情。 –