While loop error


Continuing the discussion from Loops 8/19; You Own While/Else:

from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
print random_number 

while guesses_left> 0:
    guess= int(raw_input("Your guess"))
    if guess==random_number:
        print 'You Win!'
    guesses_left -=1
    if guesses_left<0:
        print 'You Lose!'

can u please help with mistake I am doing
I do not get out of loop even after 3 guesses


Look at your indention, your else statement is not inside your while loop.

I might have edited your question to see your indention


And it shouldn't be! We have while-else's in Python!

But in the screenshot it is, which makes the else part of an if-else instead of a while-else.


I looked at the code below the image, there the else should be in the while loop, otherwise your guesses never decrease