Your own while else


#1

from random import randint

Generates a number from 1 through 10 inclusive

guesses_left = 3
while guesses_left > 0:
random_number = randint(1, 10)
print random_number
guess = int(raw_input("Guess a number "))
if guess != random_number:
guesses_left -= 1
if guesses_left == 0:
print "You lose."
break
else:
print "You win!"
break
my code works, but I keep getting an error message.


LOOPS_Your own while / else
#2

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