import random
import time
def set_difficulty():
while True:
print("Choose a difficulty level:")
print("1. Easy (1-10)")
print("2. Medium (1-50)")
print("3. Hard (1-100)")
difficulty = input("Enter 1, 2, or 3: ")
if difficulty == '1':
return 10
elif difficulty == '2':
return 50
elif difficulty == '3':
return 100
else:
print("Invalid choice. Please choose 1, 2, or 3.")
def play_game(range_limit, best_score):
number_to_guess = random.randint(1, range_limit)
number_of_guesses = 0
guessed_correctly = False
start_time = time.time()
hint_threshold = 5
print(f"I am thinking of a number between 1 and {range_limit}. You have 60 seconds to guess
it.")
while not guessed_correctly:
if time.time() - start_time > 60:
print("Time's up! You didn't guess the number in time.")
break
try:
guess = int(input("Take a guess: "))
number_of_guesses += 1
if guess < number_to_guess:
print("Your guess is too low.")
elif guess > number_to_guess:
print("Your guess is too high.")
else:
guessed_correctly = True
print(f"Good job! You guessed the number in {number_of_guesses} tries.")
if best_score is None or number_of_guesses < best_score:
best_score = number_of_guesses
print("Congratulations! You've set a new best score!")
except ValueError:
print("Please enter a valid number.")
if number_of_guesses == hint_threshold:
hint = "even" if number_to_guess % 2 == 0 else "odd"
print(f"Hint: The number is {hint}.")
return number_of_guesses, best_score
def guessing_game():
print("Welcome to the Enhanced Guessing Game!")
play_again = True
total_score = 0
rounds_played = 0
best_score = None
while play_again:
range_limit = set_difficulty()
number_of_guesses, best_score = play_game(range_limit, best_score)
total_score += number_of_guesses
rounds_played += 1
print(f"Your total score after {rounds_played} round(s) is {total_score} guesses.")
if best_score is not None:
print(f"The best score so far is {best_score} guesses.")
again = input("Do you want to play again? (yes/no): ").lower()
if again != 'yes':
play_again = False
print("Thanks for playing the Enhanced Guessing Game!")
# Run the game
guessing_game()