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

时间:2015-02-12 23:15:00

标签: python

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

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

1 个答案:

答案 0 :(得分:1)

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