dimanche 14 août 2022

Newbie question. Guess a number - code not working

    import random

    def guess(x):
random_number = random.randint(1, x)
guess = 0
while guess != random_number:
    guess = int(input(f"Guess a number between 1 and {x}: "))
    if guess > random_number:
        print(f"{guess} is incorrect, try lower!")
    elif guess < random_number:
        print(f"{guess} is incorrect, try higher!")


print(f"congratulations, you have guessed {random_number} correctly!")

Please help with this code, I have no idea why it's just not working. Been trying for a few hours. I see no issue with it, but then again, I am a newbie.




Aucun commentaire:

Enregistrer un commentaire