nathanweetman

Lewis's Guessing Game

Feb 28th, 2024
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. import random
  2.  
  3. def get_num():
  4.     while True:
  5.         try:
  6.             guess = input("Input your guess: ")
  7.             guess = int(guess)
  8.         except ValueError:
  9.             print(f"{guess} isn't a number you twat!")
  10.             continue
  11.         return guess
  12.  
  13. rand = random.randint(0, 100)
  14.  
  15. guess_is_correct = False
  16. while guess_is_correct == False:
  17.     guess = get_num()
  18.     if guess < rand:
  19.         print("Too low!")
  20.     elif guess > rand:
  21.         print("Too big!")
  22.     else:
  23.         print("You won!")
  24.         guess_is_correct = True
Add Comment
Please, Sign In to add comment