vendredi 9 juin 2017

Can someone tell why the output is wrong (Only if else statement in python)? [duplicate]

This question already has an answer here:

I am new to python and I am getting a problem in if else statement. Please tell me if I am proceeding in the wrong direction.

print "Enter your Age: ",
age = raw_input()
print age
if age < 18:
    print "young"
elif age < 65 and age >= 18:
    print "adult"
elif age >= 65:
    print "aged"

First Output

E:\Python27\python.exe E:/python/code/Check/ex7.py
Enter your Age:  10
10
aged

Process finished with exit code 0

Second Output

E:\Python27\python.exe E:/python/code/Check/ex7.py
Enter your Age:  18
18
aged

Process finished with exit code 0

Although it works perfectly fine if I give age a value in the code rather than taking input from user. I am using PyCharm Community Edition 2017

Aucun commentaire:

Enregistrer un commentaire