I need to write a number guessing game in Python. I'm trying to figure out how to check if the user input is an actual number (the number guessed). And I'm tearing my hair out. Whether I input a number or a letter character, it still prints just "Not a number" and exits.
Here's my code:
import random
x = random.randint(1,60)
y = input("I'm thinking of a number between 1 and 60, what is it? ")
if y != int():
print("Not a number")
else:
if y > x:
print("Too high")
if y < x:
print("Too low")
else:
print("Horray! You found %d!", format(x))
Aucun commentaire:
Enregistrer un commentaire