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
- random_number = generate_random_number()
- guess = capture_guess()
- attempts = 1
- while guess != random_number:
- attempts += 1
- if guess > random_number:
- guess = int(input("lower: "))
- elif guess < random_number:
- guess = int(input("higher: "))
- print("Well done!")
- print("You guessed the random number in", attempts, "attempts.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement