0

I'm a beginner in python and I'm currently working on exercise 36 in Learn Python 3 The Hard Way. I seem to be having one issue in my code. In this door, you're suppose you enter a room that is full with a bunch of gold coins. If you take too many, you die, and if you take too little, you also die. Whenever I run this part of the code I get this error. I have searched this error up and nothing makes sense. Should I be adding something else? Can anyone help?

TypeError: '>=' not supported between instances of 'str' and 'int'

Here is part of my code:

def door3():
    choice = input("Type in your number> ")

    if choice >= 1000:
        print("You took too much.")
    elif choice <= 83:
        print("You took too little.")
    else:
        print("You have taken a right amount.")

door3()
Seb
  • 1

2 Answers2

0

The reason for the error is probably because the function "input" returns a string. So it throws an error.

So try this -

choice = int(input("Type in your number> "))

if choice >= 1000:
    print("You took too much.")
elif choice <= 83:
    print("You took too little.")
else:
    print("You have taken a right amount.")
deateaterOG
  • 111
  • 1
  • 3
  • 9
0

Make this choice = int(input("Type in your number> "))

In you code y input like string format. When you are using ><= you needs integer or float format

miyamamur
  • 1
  • 1