Your own while / else - "Did you include an else for the while loop?" - Python


#1



I'm having trouble with the Python Lesson on Loops 14.8. It's the "Your own while / else".
https://www.codecademy.com/courses/python-beginner-en-cxMGf/0/8?curriculum_id=4f89dab3d788890003000096#

The code works buy Codeacademy says, "Did you include an else for the while loop?" I've tried moving "guesses_left -= 1" in different spots and I can't get it to work. Does anyone know where the "guesses_left -= 1" is suppose to go?


1   from random import randint
2   random_number = randint(1, 10)
3   guesses_left = 3
4   count = 0
5   while guesses_left > 0:
6       guess = int(raw_input("Guess a # 1-10: "))
7       num = random.randint(1, 6)   
8    if num == 6 or num == 1:
9        print "You win!"
10        break
11    else:
12        guesses_left -= 1
13       print "You lose."


#2

Your else above is in the if statement. Move it left to line up with while. Indentation is critical so make sure you have the correct indents on all the lines.


#3

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