Loops - Your own While / Else - Syntax error - Please help


#1

I have created my code but I get a syntax error. I have gone back and made sure my else was in alignment with while. I know the error message says it is on line13, where the else: code is, but I cannot see any indentation error. Can anyone help please?

Code:

Error Message:

Thanks everyone
Josie


#2

Hi the indent of guesses_left is not correct


#4

@ wizmarco.........Thank you, I went back line by line and corrected my indents. Now it has allowed me to complete the code, I am a little confused though. My code tells me I have 3 guesses and if I am correct in that, then how was I allowed to guess 8 times before the console says "You win!".............Can anyone explain?

Code:

Console:

Thanks
Josie


#5

Pull the guesses_left -= 1 back and align it to the same level as if

from random import randint

random_number = randint(1,10)

guess_left = 3

while guess_left > 0:
    guess = input()

    if guess == random_number:
        print "win"
        break
    guess_left -= 1

else:
    print "loose"

#6

@ frozentofu.........that worked, thank you :smile: