2017-02-18 72 views
-3
rawAge = input("Enter your age: ") 

age = int(rawAge) 

if age > 20: 
    print("You are older than 20 years old") 
    else: 
    print("You are too young") 

我越來越:其他:語法錯誤的Python

C:\Python36\programs>py test.py 
    File "test.py", line 8 
    else: 
    ^
SyntaxError: invalid syntax 

每一個地方我看它告訴我不喜歡這樣,我缺少什麼?

+0

你的其他不正確縮進的問題。它應該與if子句排成一行 – Neelik

+0

'else:'應該像'if:'一樣縮進,所以左邊有四個空格。 –

回答

3
rawAge = input("Enter your age: ") 

age = int(rawAge) 

if age > 20: 
    print("You are older than 20 years old") 
else: 
    print("You are too young") 

縮進

+0

感謝剛剛注意到這個問題在Python中,我的IDE格式不正確。 – WastedHat