14/8 Where is the mistake, why does is always take the else?


Could somebody give me a tip?
I cant figure out why my loop always goes to the else case and stops.

from random import randint

# Generates a number from 1 through 10 inclusive
random_number = randint(1, 10)

guesses_left = 3
# Start your game!
guess = int(raw_input("Your guess: "))
while guesses_left <= 0:
    if guess == random_number:
        print "You win!"
        guesses_left -=1
        print "You lose."


At the moment it is saying if guesses_left are less than or equal to = 0, this is False as 3 is more than 0.


when you fix what @jagking suggest, the only way for your program to end is the user guessing the right input, if the user guesses the wrong number, guesses_left is not reduced while it should


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