Elif给出的python语法无效?

Elif给出的python语法无效?,python,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

这是我一直在使用的代码,但它不起作用,因为它说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!')
age=int(输入('你几岁?:'))
如果年龄=16岁
print(‘欢迎来到课程的高级部分!')
elif:password=int(输入('请输入密码以进入精英成员部分:')):
如果密码==('muffin'):
打印(“解锁程序的秘密部分做得很好”)
其他:
打印('你不能通过!')

elif
需要一个条件(即
elif 7>5:
…)而且
elif
不能跟在
的后面,而且必须跟在
的if
elif
条件后面

在您的例子中,您的
elif
没有条件,因此python不知道该做什么


你的
elif
也跟着你的
else
我不确定你到底期望它做什么…

你的
elif
没有条件。否则…什么

这看起来像是试图使用
elif
。这是真的吗

elif age >= 16:
根据您的
if
,这是有意义的

此外,
elif
else
之前。如果您使用的是
elif
,则它需要出现在
If
之后,而在
else
之前:

if ...
elif ...
else ...

如上所述,确保为
elif
语句设置条件,并将其置于
if
else
之间。当用户年龄为16岁时,您的语句也可能会遇到问题,因为此时您的
if
else
在技术上都符合要求。

elif应该始终位于else之前,并且应该有自己的布尔语句。其他人指出您误用了if、elif和else。但我注意到的另一件事是,似乎你打算在这里使用if和else会耗尽所有年龄值(好吧,也许不是NaNs),拥有第三个条件没有任何意义。此外,如果年龄==16,则if和else都为真
if ...
elif ...
else ...