Am trying to get a simple program that will work out and state if a user is the same age, older or younger but I can't get it to work properly. Where am I going wrong please?
print('Hello! I am your faithful computer!')
Person=input('Whats your name?')
print('Hello,', Person)
Age = (input('How old are you?'))
if Age == '9':
print ('We are the same age!')
elif Age < '9':
print ('You are younger than me')
else Age > '9':
print ('You are older than me')
CodePudding user response:
You are getting the input as text, and you can't use > nor < with text.
To fix it you need to convert the variable Age to integer.
CodePudding user response:
print('Hello! I am your faithful computer!')
Person=input('Whats your name?')
print('Hello,', Person)
# your input now is an integer
Age = (int(input('How old are you?')))
# all comparisons must be between numbers
if Age == 9:
print ('We are the same age!')
elif Age < 9:
print ('You are younger than me')
elif Age > 9:
print ('You are older than me')