# 8. Your own while/else. Why is it when I put in a number > 3 it says I am wrong?

#1

So here is my code so far. When I put in 1, 1, 1 in the console it let me pass for this section but when I actually put in something greater than 3 it did not. Why did it do that?

``````from random import randint

random_number = randint(1, 10)

guesses_left = 3
while guesses_left > 0:
guess = int(raw_input("Your guess: "))
if guess > 3:
print 'You win!'
break
guesses_left -= 1
else:
print 'You Lose'``````

#2

this line here is the reason why. Is that the condition upon which a user wins this game?

#3

from random import randint

guesses_left = 3

# Start your game!

while guesses_left > 0:
random_number = randint(1, 10)
choice = int(raw_input("enter something"))
if choice == random_number:
print "you win!"
break
elif guesses_left == 1:
print "You lose"
break
else:
guesses_left -=1
print "keep trying"

# i wonder if this is another way of doing the excercise

#4

codecademy should accept this as an answer

#5

this worked for me

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 = int(raw_input("Your guess: "))
if guess == random_number:
print 'You win!'
break
guesses_left -= 1
else:
print 'You lose.'

#6

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