-4
print("Hello there")
name=input("What is your name?")
print("Welcome to the some game, " + name + "!")
print("I'm going to ask you some basic questions so that we could work together")
age=input("Your age")
if age >= 14 and age < 41:
    print("K")
else:
    print("Sorry bruh")
print("Thanks")

keeps showing me "Sorry bruh" at the end when entered 15. Why? What's wrong?

White Shadow
  • 444
  • 2
  • 10
  • 26
  • ussing python 3 I get `TypeError: unorderable types: str() >= int()` and using python 2 I get no problem. (other then not being able to use a string name) – Tadhg McDonald-Jensen Jun 12 '16 at 19:24
  • @Tadhg, you get no error but you get the wrong answer. Python 2 compares the _names_ of types when they are incompatible! (`"int" < "str"`) – alexis Jun 12 '16 at 20:03
  • @alexis no, on python 2 if you type in `15` for the age it prints out `K`, on python 3 it raises an error when trying to compare the str to int, so I am unable to reproduce '''showing me "Sorry bruh" at the end when entered 15.''' – Tadhg McDonald-Jensen Jun 12 '16 at 20:07
  • Possible duplicate of [Behaviour of raw\_input()](http://stackoverflow.com/questions/17638087/behaviour-of-raw-input) – alexis Jun 12 '16 at 20:09
  • 1
    Oh no wait, you're right: On python 2, `input( )` will convert to `int`. But this is python 3-- obviously not the only problem with it. – alexis Jun 12 '16 at 20:17

3 Answers3

4

Cast your input to int:

age = int(input("Your age"))

You could add a try-except. Your condition should equally be evaluated on or not and

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
0

Either you use Python3 and you need to cast with int(input("Your age")) or you use Python2 and then you need to use raw_input to read the name: name=raw_input("What is your name?")

Maxime Chéramy
  • 17,761
  • 8
  • 54
  • 75
0

Ok , so you can try this code in python2.7 and it will work as you desired:

print("Hello there")
name=raw_input("What is your name?")
print("Welcome to the some game, " + name + "!")
print("I'm going to ask you some basic questions so that we could work together")
age=input("Your age")
if age >= 14 and age < 41:
    print("K")
else:
    print("Sorry bruh")
print("Thanks")
White Shadow
  • 444
  • 2
  • 10
  • 26