-2

This is my code

Name=input("Hi please enter your name: ")

print("Hi " + Name)

Age=input(Name + " could you please Enter your age: ")

if Age > 40:
    print(" Wow you are so old")
if Age < 18:
    print("Wow you are so you")

When I try to run it is gives me an error that '>' not supported between instances of 'str' and 'int'

  • `Age= int(input(Name + " could you please Enter your age: "))` `input()` function gives `str` i.e. string, you need to convert it to integer. What you are currently doing is something `'26'>40` and python is confused about how to compare string with an integer. – Epsi95 Aug 26 '21 at 14:32
  • `input()` returns a string, you'll need to coerce it to an int. – blackbrandt Aug 26 '21 at 14:33

1 Answers1

0

Input returns a string. You need to convert it to an integer.

If your input is always an integer this naive fix would work:

Name=input("Hi please enter your name: ")

print("Hi " + Name)

Age=int(input(Name + " could you please Enter your age: "))


if Age > 40:
    print(" Wow you are so old")
if Age < 18:
    print("Wow you are so you")
tjallo
  • 781
  • 6
  • 25
  • Hi thanks for the fix but I have another problem when I put in the age I don't get the print with the age. – mahdimaster Aug 26 '21 at 14:37
  • @mahdimaster What age did you input…? – deceze Aug 26 '21 at 14:38
  • The age I inputted is 32. – mahdimaster Aug 26 '21 at 14:40
  • 1
    @mahdimaster And which condition do you think 32 should match to print what…? – deceze Aug 26 '21 at 14:40
  • You need to be more clear with your question. If you want to print out the age variable you have to add `print(Age)` after your `Age=int(input...` line (and correctly indeted/placed if you want it add in a certain `if` statement). Also make sure you always enter only an integer (1,2,3...,99999999) when asked for your age, otherwise to conversion will fail. Please don't forget to accept my answer if it has solved the question. – tjallo Aug 26 '21 at 14:40