Last answered:

10 Jul 2023

Posted on:

09 Jul 2023

0

Question 2 code didn't work

What is wrong with my answer

secret_number = '8'
guess = input('guess the number! Hint: it\'s between 1 and 10\
\n >>>> ')
guess = int(guess)
if guess == secret_number :
    print('It\'s 8! You\'re right.')
elif guess > secret_number and guess <= 10:
    print('It\'s too high. Sorry you lose')
elif guess < secret_number and guess >= 1:
    print('It\'s too low. Sorry you lose')
else:
    print('You\'r not a winner')

1 answers ( 0 marked as helpful)
Instructor
Posted on:

10 Jul 2023

0

Hey Ahmed,


Thank you for reaching out.


The error you get reads:

'>' not supported between instances of 'int' and 'str'

This means you have put the '>' symbol between an integer and a string variable. Or, in other words, you are trying to compare an integer with a string.


Notice your definition of the secret_number variable - a string with the number 8. Now study your definition of the guess variable - it's a string that you've then converted to an integer. In your if-statements, therefore, you are comparing an integer (guess) with a string (secret_number).


The only change you need to make to run your code successfully is to change the first line of code from

secret_number = '8'

to

secret_number = 8

In that way, you'll compare an integer variable with another integer.


Hope this helps.


Kind regards,

365 Hristina

Submit an answer