Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- !import random
- from art import logo
- def is_guessed(n1, n2):
- if n1 == n2:
- print(f"You got it! The answer was {n1}!")
- return False
- elif n1 > n2:
- print("Too high")
- print("Guess again")
- return True
- else:
- print("Too low")
- print("Guess again")
- return True
- print(logo)
- print("Welcome to the Number Guessing Game!")
- print("I'm thinking of a number between 1 and 100")
- decision = input("Choose a difficulty. Type 'easy' or 'hard': ")
- if decision == "easy":
- lives = 10
- number = random.randint(1,101)
- print(f"You have {lives} attempts remaining to guess the number.")
- guess = int(input("Make a guess: "))
- should_continue = is_guessed(guess, number)
- while should_continue:
- if lives > 1:
- lives -= 1
- print(f"You have {lives} attempts remaining to guess the number.")
- guess = int(input("Make a guess: "))
- should_continue = is_guessed(guess, number)
- else:
- print(f"You've run out of guesses, you lose")
- should_continue = False
- elif decision == "hard":
- lives = 5
- number = random.randint(1, 101)
- print(f"You have {lives} attempts remaining to guess the number.")
- guess = int(input("Make a guess: "))
- should_continue = is_guessed(guess, number)
- while should_continue:
- if lives > 1:
- lives -= 1
- print(f"You have {lives} attempts remaining to guess the number.")
- guess = int(input("Make a guess: "))
- should_continue = is_guessed(guess, number)
- else:
- print(f"You've run out of guesses, you lose")
- should_continue = False
Advertisement
Add Comment
Please, Sign In to add comment