vendredi 15 novembre 2019

How to return the print function "You win" after user guess wrong on first guess but enters correctly after

So i am tryting to create a number guessing game. If they user inputs the first try then it prints "You win!" as wanted. When they enter incorrectly it prompts them to try again, however when guessed correctly after the first time then it keeps prompting them. How do I make it so it prints "You win"!

if play == "Y":
    print("Great! Lets play")
    guess = int(input("I am thinking of a number between 1 and 20\nWhat is your first guess? "))
    while guess != number:
        guess = input("Guess again: ")
    if guess == number:
        print("You win!")

Aucun commentaire:

Enregistrer un commentaire