Advertisement
earlution

Number guessing game v0.2

Jun 12th, 2020
972
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. import random
  2.  
  3. def generate_random_number():
  4.     random_number = random.randint(1,100)
  5.     return random_number
  6.  
  7. random_number = generate_random_number()
  8. guess = int(input("Guess a number between 1 and 100: "))
  9. attempts = 1
  10.  
  11. while guess != random_number:
  12.     attempts += 1
  13.     if guess > random_number:
  14.         guess = int(input("lower: "))
  15.     elif guess < random_number:
  16.         guess = int(input("higher: "))
  17.  
  18. print("Well done!")
  19. print("You guessed the random number in",  attempts, "attempts.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement