mardi 31 mars 2020

Python3 : ifelse statement error in Python 3 code [closed]

Hello There,

I am a beginner python developer. I made a simple python3 code which have three case.

  1. if age = less than 18 then print you cannot drive
  2. when age = 18 print we will think about you
  3. when age = more than 18 you can drive

    • and if the input or age = more than 100 then it should print invalid age


    and this program works very well but if i use nested if else statement it doesn't work here is the code :

age calculator for driving

print()
print("\t Age requirement for Driving")
age = int(input(" Enter Your Age : "))
if age < 18:
    print(" Sorry, You're under age. You cannot drive")
elif age == 18:
    print(" Sorry, we cannot Decide. we will think about you :) ")
elif age > 100:
    print(" Invalid Age !!! Your are not immortal ;)")
else:
    print(" Congratulation !!! You can Drive")

Code with Nested if else statement

print()
print("\t Age requirement for Driving")
age = int(input(" Enter Your Age : "))
if age < 18:
    print(" Sorry, You're under age. You cannot drive")
    if age > 100:
        print(" Invalid Age")
elif age == 18:
    print(" Sorry, we cannot Decide. we will think about you :) ")
else:
    print(" Congratulation !!! You can Drive")

this code doesn't work please help !!!

Aucun commentaire:

Enregistrer un commentaire