Am I allowing 3 guesses or 2?
I am learning Python on Codecademy, and I am supposed to give the user 3
guesses before showing "you lose". I think my code allows 3 entries, but
the website shows "Oops, try again! Did you allow the user 3 guesses, or
did you incorrectly detect a correct guess?" unless the user guesses
correctly within 3 trials. Can someone tell me what's wrong?
from random import randrange
random_number = randrange(1, 10)
count = 0
# Start your game!
guess= int(raw_input("Please type your number here:"))
while count < 2:
if guess==random_number:
print "You win!"
break
else:
guess=int(raw_input("Please guess again:"))
count+=1
else:
print "You lose!"
print random_number
No comments:
Post a Comment