0

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
>>>
Abhijit
  • 21
  • 1

1 Answers1

0

Try this. You should have if age<12 inside the parent if

print('Name?')
name=input()
if name=='Alex':
    print('ok')
    print('Age?')
    age=input()
    if age<12:
       print('Nice')
Arghya Saha
  • 5,599
  • 4
  • 26
  • 48