8. Code does what it's supposed to do but, I'm still getting an error?


#1

The code does what is is supposed to but I keep getting the error:
"Oops, try again. Make sure to decrement guesses_left!"

from random import randint

random_number = randint(1, 10)
print random_number

guesses_left = 3
print "Guesses left",guesses_left
while guesses_left > 0:
    guess = int(raw_input("Your guess: "))
    if guess != random_number:
        guesses_left = (guesses_left -1)
        print "Guesses left",guesses_left
    if guess == random_number:
        print "You win!"
        break
    if guesses_left <= 0:
        print "You Loose!"
        break
else:
    print "You loose!"

I know that I am doing something different then the lesson wants me to because "else" is unneeded, and the directions say to have it.
Thanks for the help you guys:sweat_smile:


#2

the problem is in this line:

guesses_left = (guesses_left -1)

don't use any brackets on this line. Also, your you loose:

print "You Loose!"

needs a second look


#3

Thank you for the help. :smile:
Would you be able to explain to me why the brackets messed it up?


#4

I think the checking script of the exercise didn't like them. I don't see any reason why this normally wouldn't work. Except i won't use them, you have only one operation (-), so no need to use brackets


#5

Okay, Thank you :blush: