S
S
Staffic2020-07-17 23:14:13
Python
Staffic, 2020-07-17 23:14:13

Problems with python code?

Can't execute code:

import random
secret = random.randint(1, 99)
guess = 0
tries = 0
print ("Эй на палубе! Я ужасный пират Робертс, и у меня есть секрет!")
print ("Это число от 1 до 99. Я дам тебе 6 попыток.")
while guess != secret and tries < 6:
    guess = input("Твой вариант?")
    if guess < secret:
        print ("Это слишком мало, презренный пес!")
    elif guess > secret:
        print ("Это слишком много, сухопутная крыса!")

    tries = tries + 1

if guess == secret:
    print ("Хватит! Ты угадал мой секрет!")
else:
    print ("Попытки кончились!")
    print ("Это число "), secret

Gives an error message:
Traceback (most recent call last):
  File "D:\2.py", line 9, in <module>
    if guess < secret:
TypeError: '<' not supported between instances of 'str' and 'int'

Help me please...

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
soremix, 2020-07-17
@Staffic

TypeError: '<' not supported between instances of 'str' and 'int

Type error: character "<" is not supported between "string" and "number"
guess you have a string
secret - number

W
Web Dentist, 2020-07-17
@kgb_zor

guess = int(input("Твой вариант?"))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question