Python Forum
'<' not supported between instances of 'str' and 'int'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'<' not supported between instances of 'str' and 'int'
#1
import random

secret = random.randint(1, 99)
guess = 0
tries = 0
print("AHOY! I'm the Dread Pirate Roberts, and I have a secret")
print("It's the number from 1 to 99..and I'll give you 6 chances")

while guess != secret and tries < 6:
    guess = input("What's your guess? ")
    if guess < secret:
        print("To Low...You creep")

    elif guess > secret:
        print("Too High, Douchbag")
        tries = tries + 1

        if guess == secret:
            print("Avast! You finally got it!")

        else:
            print("No more chances...Play again later")
            print("The secret number was", secret)
Reply
#2
input returns string and therefore you comparing string with int which for quite obvious reasons is not possible. You should convert input to int.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort Function: <' not supported between instances of 'float' and 'tuple' quest 2 7,971 Apr-30-2021, 07:37 PM
Last Post: quest
Exclamation TypeError: '>=' not supported between instances of 'int' and 'str' helpme1 11 8,677 Mar-11-2021, 11:13 AM
Last Post: helpme1
  Type error: '>' not supported between instances of 'NoneType' and 'int' spalisetty06 1 10,427 Apr-29-2020, 06:41 AM
Last Post: buran
  TypeError: '<' not supported between instances of 'str' and 'int' Svensation 5 8,670 Jan-20-2020, 08:12 PM
Last Post: buran
  TypeError: Not supported between instances of 'function' and 'int' palladium 9 19,399 Dec-06-2019, 12:40 AM
Last Post: palladium
  TypeError: '>=' not supported between instances of 'str' and 'int' AsadZ 8 10,338 Aug-20-2019, 11:45 AM
Last Post: ThomasL
  '>' not supported between instances of 'str' and 'int' graham23s 2 3,925 May-11-2019, 07:09 PM
Last Post: micseydel
  Newbie Question re "TypeError: '<' not supported between instances of 'list' and 'int sr12 8 12,945 Apr-11-2019, 08:19 PM
Last Post: sr12
  TypeError: '<' not supported between instances of 'int' and 'builtin_function_or_meth yann2771 1 5,512 Mar-05-2019, 09:51 PM
Last Post: stranac
  '<=' not supported between instances of 'str' and 'int' Loom 1 7,739 Aug-11-2018, 07:34 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020