Invalid syntax


#1

why does it say that else is invalid syntax

from random import randint

Generates a number from 1 through 10 inclusive

random_number = randint(1, 10)

guesses_left = 3

Start your game!

while guesses_left > 0:
guess = input('Your guess?')
if guess == random_number:
print 'you win'
break
guesses_left = guesses_left - 1
else:
print 'you lose'
break


#2

Well we can't see your proper formatting in the code, I am guessing you have something wrong with your indents, probably your 'break' call is in line with your 'if'. It needs to be inline with your 'while'. Also, you needed a '-=' instead of just an '-' in your guesses_left, otherwise it will loop forever.

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