Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def generate_random_number():
- random_number = random.randint(1,100)
- return random_number
- def capture_guess():
- guess = int(input("Guess a number between 1 and 100: "))
- return guess
- def evaluate_user_guess(guess, random_number):
- if guess > random_number:
- guess = int(input("lower: "))
- elif guess < random_number:
- guess = int(input("higher: "))
- return guess
- def guess_random_number(guess, random_number):
- attempts = 1
- while guess != random_number:
- guess = evaluate_user_guess(guess, random_number)
- attempts += 1
- return attempts
- random_number = generate_random_number()
- guess = capture_guess()
- attempts = guess_random_number(guess, random_number)
- print("Well done!")
- print("You guessed the random number in", attempts, "attempts.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement