# What is wrong with this code for a while/ else loop

#1

from random import randint

# Generates a number from 1 through 10 inclusive

random_number = randint(1, 10)

guesses_left = 3

while guesses_left > 0 :

``````guess = int( raw_input("Your guess: ")
guesses_left = guesses_left-1

if  (guess == random_number) :
print "You win"
break``````

#2

Hi first you should put your `guesses_left = guesses_left-1` after `break` and then add a `else statement` to `print "You lose"`

#3

from random import randint

# Generates a number from 1 through 10 inclusive

random_number = randint(1, 10)

guesses_left = 3

while guesses_left > 0 :

``````guess = int( raw_input("Your guess: ")

if  (guess == random_number) :
print "You win"
break
guesses_left = guesses_left-1

else :
print"you lose"``````

I wrote this now. but the console shows an error at line if (guess == random_number) : . any insights?

#4

in your `guess = int( raw_input("Your guess: ")` is missing one `")"` so its should be like that
`guess = int( raw_input("Your guess: "))` and in the `else statement` you should `print "You lose "` with a upcase `Y` so your code should be like that

``````while guesses_left > 0 :