I am having a very hard time with this section of loops. The instructions are; Use a while loop to let the user keep guessing so long as guesses_left is greater than zero.
Ask the user for their guess, just like the second example above.
If they guess correctly, print ‘You win!’ and break.
Decrement guesses_left by one.
Use an else: case after your while loop to print You lose.

And I am not sure what they are saying.

This is my code:

while guesses_left > 0:
    guess = int(raw_input("Your guess: "))
    print guess
    if guess == random_number: 
        print "You win!"
    guess_left -= 1
        print "You lose."

But it didn’t works. So if everyone can help, please help me.


each iteration of the loop you inform the user they lost, why?

you only want to inform the user they lost after they ran out of guesses (loop finished)


Okay so much can I do that.


i hope you can do this, yes :slight_smile:


I don’t get what you mean.


well, in python, what determines if something is nested inside or outside a loop?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.