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幫助你弄清楚這種事情。 –