Python Forum
'<' not supported between instances of 'str' and 'int' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: '<' not supported between instances of 'str' and 'int' (/thread-17394.html)



'<' not supported between instances of 'str' and 'int' - jayaherkar - Apr-09-2019

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)



RE: '<' not supported between instances of 'str' and 'int' - perfringo - Apr-09-2019

input returns string and therefore you comparing string with int which for quite obvious reasons is not possible. You should convert input to int.