dimanche 12 août 2018

0001. elif skipped[beginner]

Please let me know why elif is being ignored? I did get several hits on this topic, however those were not much of help.

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
>>>

Aucun commentaire:

Enregistrer un commentaire