gpt4 book ai didi

python - 为什么这段代码会跳出循环?

转载 作者:行者123 更新时间:2023-12-03 08:12:50 26 4
gpt4 key购买 nike

import math
t=raw_input()
k=[]
a=0
for i in range(0,int(t)):
s=raw_input()
b=1
c=1
a=int(s)
if a==0:
continue
else:
d=math.atan(float(1)/b) + math.atan(float(1)/c)
v=math.atan(float(1)/a)
print v
print d
print float(v)
print float(d)
while():
if float(v)== float(d):
break
b=b+1
c=c+1
d=math.atan(float(1)/float(b)) + math.atan(float(1)/float(c))
print d
k.append(int(b)+int(c))

for i in range(0,int(t)):
print k[i]

因为很明显 float(v) != float(d)直到 b变为2而 c变为3。

最佳答案

您的while循环在一个空元组上进行测试,其结果为False。因此,while循环中的语句将永远不会执行:

如果要让while循环运行直到遇到break语句,请执行以下操作:

while True:
if (some_condition):
break
else:
# Do stuff...

关于python - 为什么这段代码会跳出循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/994729/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com