Can anyone help me figure out why I'm getting this error message. It prints just fine to the console but it doesn't seem to like my else statement. Thanks!
The else should be under the while, not the if. Back of the indentation.
Thank you for your prompt reply. I moved the else under the while and still getting the same error message. I played with the indentation for a bit thinking the if should be under while as well but no luck. I'm stumped.
- A link to the exercise
- Your code
Then we can take a better look. Thank you.
from random import randint # Generates a number from 1 through 10 inclusive random_number = randint(1, 10) guesses_left = 3 # Start your game! while guesses_left > 0: guess = int(raw_input("Your guess: ")) guesses_left -= 1 if guess == random_number: print "You win!" break else: print "You loose."
It passed this way but I went back a few minutes later and gives error msg again with same indentation.
I made this change, and the code ran to completion with no errors:
if guess == random_number: print "You win!" break elif guesses_left > 0: print 'Guess again.'
Did you print the "You lose." message?
Your code has a misspelled word, 'loose' => 'lose'
Thank you much for you help. I realized my code only passed when I guessed correctly. I corrected my spelling error, runs with no issues now.