Advertisement
earlution

Number guessing game v0.4

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