import random

def play_game():
  # Set game parameters
  lower_bound = 1
  upper_bound = 100
  max_attempts = 10

  # Generate random number
  secret_number = random.randint(lower_bound, upper_bound)

  # Start the game loop
  for attempt in range(max_attempts):
    guess_str = input(f"Guess a number between {lower_bound} and {upper_bound} (Attempts remaining: {max_attempts - attempt}): ")

    try:
      guess = int(guess_str)
    except ValueError:
      print("Invalid input. Please enter a valid number.")
      continue

    # Check guess and provide feedback
    if guess == secret_number:
      print("Congratulations! You guessed the number!")
      return True
    elif guess < secret_number:
      print("Too low! Try again.")
    else:
      print("Too high! Try again.")

  # User ran out of attempts
  print(f"Sorry, you ran out of attempts. The number was {secret_number}.")
  return True

# Play the game and offer another round
if play_game():
  play_again = input("Do you want to play again? (y/n): ")
  if play_again.lower() == 'y':
    play_game()

  if play_again.lower() == 'n': 
    print("Thanks for playing!")