2015-09-28 54 views
-1

這是我一直在使用的代碼,但它不工作,因爲它說elif語句是無效的語法。任何人都可以幫助我,因爲我是一名Python初學者。Elif給予無效的語法python?

age = int(input('How old are you?: ')) 
if age <= 16: 
    print ('You are too young to enter this section of the program!') 
else: 
    age >= 16 
    print ('Welcome to the advanced section of the program!') 

elif: password = int(input('please enter the password to enter the elite members section: ')): 
    if password == ('muffin'): 
     print ('Well done for unlocking the secret part of the program') 
    else: 
      print ('You shall not pass!') 
+0

elif應該總是在else之前,並且應該有它自己的布爾語句 –

+0

其他人指出了你對if,elif,else的濫用。但我注意到的另一件事是,看起來你的**意圖**使用if和else會在這裏耗盡所有的年齡值(好的,也許不是NaNs),擁有第三個條件沒有任何用處。另外,如果年齡== 16 – HexedAgain

回答

6

elif需要的條件(即elif 7 > 5: ....)也是一個elif不能遵循一個else必須遵循ifelif條件

你的情況你elif有沒有條件,所以蟒蛇不知道該怎麼辦

您的elif也跟在您的else我不知道你真正期望它做什麼..

1

您的elif沒有條件。否則,如果... 什麼

else: 
    age >= 16 

看起來像elif的嘗試。如果這真的是

elif age >= 16: 

這是有道理的基礎上你的if

此外,elifelse之前。如果您正在使用elif,它需要if後發生但之前else:如上所述

if ... 
elif ... 
else ... 
+0

dang方式來讀取行之間的方式,你的if和else都是真的:P +1 –

0

,一定有你的ifelse之間爲您elif語句的條件,以及地方吧。當用戶的年齡爲16歲時,您也可能會遇到問題,因爲此時您的ifelse在技術上都合格。