Your own while / else - loops - python


#1

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

can anybody tell me why it doesn't work?


#2

Perhaps you would like to explain how you would like it to act differently?

Also, does your code really look like that? Make sure your post accurately represents your code, otherwise we aren't looking at the code that you're having trouble with.


#5

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

this worked