Advertisement
earlution

Number guessing game v0.3

Jun 12th, 2020
1,108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.58 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. def capture_guess():
  8.     guess = int(input("Guess a number between 1 and 100: "))
  9.     return guess
  10.    
  11. random_number = generate_random_number()
  12. guess = capture_guess()
  13. attempts = 1
  14.  
  15. while guess != random_number:
  16.     attempts += 1
  17.     if guess > random_number:
  18.         guess = int(input("lower: "))
  19.     elif guess < random_number:
  20.         guess = int(input("higher: "))
  21.  
  22. print("Well done!")
  23. print("You guessed the random number in",  attempts, "attempts.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement