Python Forum
elif and if - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: elif and if (/thread-9176.html)



elif and if - jlgeter2002 - Mar-25-2018

this code works fine except the last elif

elif age >= '100' and name != 'Alice':
print('you are not alice grannie')
If I enter any value between 100 and 119 it returns 'you are not Alice kiddo' however if I enter 120 or above it returns the proper value. what am I doing wrong?



print ('name please') #ask for name
name=input()
print ('age please') #ask for age
age=input()
if name == 'Alice' and age == '12':

print ('Hi Alice')


elif age < '12' and name != 'Alice':
print ('you are not alice, kiddo')
elif age > '2000' and name != 'Alice':
print ('unlike you alice is not an undead, vampire')
elif age >= '100' and name != 'Alice':
print('you are not alice grannie')


RE: elif and if - j.crater - Mar-25-2018

Please put your code in Python code tags. You can find help here.


RE: elif and if - jlgeter2002 - Mar-25-2018

this code works fine except the last elif


elif age >= '100' and name != 'Alice':
print('you are not alice grannie')
If I enter any value between 100 and 119 it returns 'you are not Alice kiddo' however if I enter 120 or above it returns the proper value. what am I doing wrong?


print ('name please') #ask for name
name=input()
print ('age please') #ask for age
age=input()
if name == 'Alice' and age == '12':

print ('Hi Alice')


elif age < '12' and name != 'Alice':
print ('you are not alice, kiddo')
elif age > '2000' and name != 'Alice':
print ('unlike you alice is not an undead, vampire')
elif age >= '100' and name != 'Alice':
print('you are not alice grannie')



RE: elif and if - wavic - Mar-25-2018

You are comparing strings, not integers.


RE: elif and if - ljmetzger - Mar-25-2018

You are doing string comparisons and you need to do numeric comparisons.

Try something like:
age = int(input('age please'))
then remove the quotes from around your number comparison values.

Lewis