import random # Initialize variables rounds = 1 user_score = 0 AI_score = 0 max_tries = 10 total_rounds = 3 print("Welcome to the Take-Away Game!") player = input("What is your name? ") print(f"Welcome, {player}! Let's see if you can guess the number before 10 guesses.") # Main game loop while rounds <= total_rounds: print(f"\n--- Round {rounds} ---") number = random.randint(1, 1000) # The number to guess guesses_left = max_tries round_won = False print(f"Guess the number between 1 and 1000. You have {guesses_left} tries.") # Loop for 10 guesses while guesses_left > 0: guess = int(input(f"You have {guesses_left} guesses left. Enter your guess: ")) guesses_left -= 1 if guess < number: print("Too low! Try again.") elif guess > number: print("Too high! Try again.") else: print("Congratulations! You've guessed the number!") round_won = True break # Check if the player won the round if round_won: print(f"Well done, {player}! You guessed the number in {max_tries - guesses_left} tries.") user_score += 1 # Increase user score else: print(f"Sorry, {player}. The correct number was {number}. You lost this round.") AI_score += 1 # AI wins the round rounds += 1 # Final score after 3 rounds print("\n--- Game Over ---") print(f"{player}'s Final Score: {user_score} | AI Score: {AI_score}") if user_score > AI_score: print(f"Congratulations, {player}! You won the game!") elif user_score < AI_score: print(f"Better luck next time, {player}. The AI won this time.") else: print(f"It's a tie! Both {player} and AI have the same score.")