Loops 8/19; You Own While/Else


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!

While loop error

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.


Please provide:

  1. A link to the exercise
  2. 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!"
    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!"
    elif guesses_left > 0:
        print 'Guess again.'

SCT message

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.

Thanks again.


A post was split to a new topic: 8/19 Does not work for me