Python – guess hidden number

Hi, I am sure there are numerous way to solve this. Here is a way:

import random
keepPlaying="y"

while keepPlaying == "y":
    print("Game start!")
    hiddenNumber = random.randint(1,100)
    userGuess=0
    while not userGuess == hiddenNumber:
        userGuess = int(input("Guess a number:"))
        if userGuess > hiddenNumber:
            print("Too high")
        elif userGuess < hiddenNumber:
            print("Too low")
        else:
            print("That's right")
    keepPlaying = input("Play again ? y or n")

Regards.

Leave a Reply

Your email address will not be published. Required fields are marked *