lundi 26 septembre 2022

Why my number guessing game does not work?

Less than one day into learning Python. I'm trying to make a simple number-guessing game, but I've run into a problem: the number is always incorrect, but there's only 10 to pick from! Here's my code for reference:

import random



def game():
    randomNum = random.randint(1, 11)
    guess = 0
    print(input("Guess a number between 1 and 10: "))
    while guess != randomNum:
        if guess == randomNum:
            print("Correct! You win!")
            break
        else:
            print(input("Incorrect, guess again: "))


game()

Any reason why this is happening?




Aucun commentaire:

Enregistrer un commentaire