Advertisement
earlution

Number guessing game v0.6

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