I'm trying to figure out how to prevent the text "Guess again." from being printed after the third guess entered is incorrect. I want the output to print "You lose." without printing "Guess again." before that happens.
from random import randint # Generates a number from 1 through 10 inclusive random_number = randint(1, 10) guesses_left = 3 # Start your game! while guesses_left > 0: guess = int(raw_input("Your guess: ")) if guess == random_number: print ("You win!") break else: print ("Guess again.") guesses_left -= 1 else: print ("You lose.")
For instance, this is what the output looks like now:
Your guess: 5
Your guess: 3
Your guess: 7
Guess again. This is what I want to not appear.