gpt4 book ai didi

python - 尝试学习 while 循环出现意外缩进和语法错误? (Python)

转载 作者:太空宇宙 更新时间:2023-11-03 17:55:41 25 4
gpt4 key购买 nike

下面的代码给了我意外的缩进,我尝试了很多变体,但我不断收到这些错误或语法错误

while True:
try:
a=int(input("Please enter a number to be counted down to: "))
b=(a-1)
for count in range (100,b,-1):
print (count)
break
except:
print ("wohoo")

最佳答案

while 循环需要一个包含的代码块:

while True:    
try:
a = int(input("Please enter a number to be counted down to: "))
b = (a-1)

for count in range(100, b, -1):
print(count)

except:
print ("wohoo")

关于python - 尝试学习 while 循环出现意外缩进和语法错误? (Python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28489702/

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