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


#1

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!"
        break
        guesses_left -=1
else: 
        print "You lose."

#2

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.


#3

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


#4

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