這是我一直在使用的代碼,但它不工作,因爲它說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!')
elif應該總是在else之前,並且應該有它自己的布爾語句 –
其他人指出了你對if,elif,else的濫用。但我注意到的另一件事是,看起來你的**意圖**使用if和else會在這裏耗盡所有的年齡值(好的,也許不是NaNs),擁有第三個條件沒有任何用處。另外,如果年齡== 16 – HexedAgain