Python 3.x 为什么我的代码没有脱离while循环?
我有这个代码来显示两个幂:Python 3.x 为什么我的代码没有脱离while循环?,python-3.x,while-loop,Python 3.x,While Loop,我有这个代码来显示两个幂: print ("How many powers of two would you like to see?") number=int(input()) values=[2] count=1 while count <= number: length=len(values) index=length-1 number=values[index]*2 values.append(number) count=count+1
print ("How many powers of two would you like to see?")
number=int(input())
values=[2]
count=1
while count <= number:
length=len(values)
index=length-1
number=values[index]*2
values.append(number)
count=count+1
print (values)
print(“您希望看到二的多少次幂?”)
number=int(输入())
值=[2]
计数=1
而count如果您查看number的值,在第40次迭代之后,count=40
但是
number = 2199023255552
number = 21430172143725346418968500981200036211228096234110672148875007767407021022498722449863967576313917162551893458351062936503742905713846280871969155149397149607869135549648461970842149210124742283755908364306092949967163882534797535118331087892154125829142392955373084335320859663305248773674411336138752
在第1000次迭代之后,count=1000
number = 2199023255552
number = 21430172143725346418968500981200036211228096234110672148875007767407021022498722449863967576313917162551893458351062936503742905713846280871969155149397149607869135549648461970842149210124742283755908364306092949967163882534797535118331087892154125829142392955373084335320859663305248773674411336138752
因此,计数永远不会超过数字,循环也永远不会中断。你可以通过不改变循环中的<代码>编号<代码>的值来改变这一点。 你比较<代码>计数可能是因为你正在改变循环中的“数字”,而不仅仅是“计数”,如果它有帮助,请考虑接受答案: