简体   繁体   English

试图学习while循环会遇到意外的缩进和语法错误? (蟒蛇)

[英]Trying to learn while loops getting unexpected indent and syntax errors? (python)

The following code gives me unexpected indent I have tried many variations but I keep getting these errors or syntax errors 以下代码为我带来了意想不到的缩进,我尝试了许多变体,但不断出现这些错误或语法错误

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")

The while loop needs a contained code block: 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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM