当我运行此代码来计算根2连分式的收敛性时:
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进行迭代。如果有任何建议,我将不胜感激。你知道吗
线路
解压
b
和b
中的元组c
,因此b
中只保存第二个int。在下一个循环步骤中,您将尝试对此int调用sum
你的意思是
相关问题 更多 >
编程相关推荐