0001. elif skipped [beginner]

时间:2018-08-12 17:35:09

标签: python-3.x if-statement flow-control

请让我知道为什么 elif 被忽略了吗? 我确实在该主题上获得了一些成功,但这些帮助不多。

print('Name?')
name=input()
if name=='Alex':
    print('ok')
    print('Age?')
    age=input()
elif age<12:
    print('Nice')

outputs:
Name?
Alex
ok
Age?
11
>>> 
Name?
Joe
Traceback (most recent call last):
  File "/home/User/Documents/python/0006.Practice_o2.py", line 7, in <module>
    elif age<12:
NameError: name 'age' is not defined
>>>

1 个答案:

答案 0 :(得分:0)

尝试一下。如果

,则您的父母中应该有 if age <12
print('Name?')
name=input()
if name=='Alex':
    print('ok')
    print('Age?')
    age=input()
    if age<12:
       print('Nice')