While loop error


#1

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 

guesses_left=3
while guesses_left> 0:
    guess= int(raw_input("Your guess"))
    if guess==random_number:
        print 'You Win!'
        break
else:
    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


#2

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

I might have edited your question to see your indention


#3

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.


#4

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