簡體   English   中英

試圖學習while循環會遇到意外的縮進和語法錯誤? (蟒蛇)

[英]Trying to learn while loops getting unexpected indent and syntax errors? (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")

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