Your own while / else - finished but unsure?


i completed this section successfully but am very bothered.

isn't this exercise meant to allow 3 guesses? but i everytime i submit the code and try 1 guess it says "You lose!". what am i not getting? the aim of this exercise? Thanks in advance!

from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)
guess = int(raw_input("Your guess: "))
guesses_left = 3
# Start your game!
while guesses_left > 0:
    if guess == random_number:
        print "You win!"
    guesses_left = guesses_left-1
    print "You lose!"


It is indeed meant to allow 3 guesses. However, at this point in time you are only asking the user for ONE guess. This means that if the user gets their ONE guess wrong, it will automatically go through all of the available guesses and print You lose! console. If the user, by some miracle guessed it correctly with with their one guess it would print You win! to the console. This will not be the case for long, since you will be adding on to this code in further exercises.


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