""" ------------------------------------------------- Project: Guess the number Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Jovan Tagore Date: 06/03/25 Python: 3.5 ------------------------------------------------- """ import random import time # variables reset_guesses = 0 rounds = 3 player_score = 0 computer_score = 0 round_number = 1 # intro and name print("----------------------------------") print("Welcome to Guess The Number") print() time.sleep(2) name = input("What is your name? ") print(f"Welcome, {name}!") time.sleep(2) print("----------------------------------") print() # explaining the game rules print("These are the game rules:") time.sleep(2) print("You'll play 3 rounds with a maximum of 10 guesses per round.") time.sleep(2) print("Guess a number between 1 and 1000. After each guess, you'll be told if it's too high, too low, or correct.") time.sleep(4) print("If you don't get your number in 10 guesses, the Computer will get a point.") time.sleep(3) print("The first player to win 2 rounds wins the game.") time.sleep(2) print() print("----------------------------------") # game loop for the rounds while round_number <= rounds: print(f"Round {round_number}:") secret_number = random.randint(1, 1000) # generate the secret number guesses_left = 10 round_winner = None # give the player 10 guesses to find the secret number while guesses_left > 0: guess = int(input(f"Guess # {11 - guesses_left}: Enter a number between 1 and 1000: ")) if guess < secret_number: print("Too low! Try again.") elif guess > secret_number: print("Too high! Try again.") else: print(f"Congratulations {name}, you guessed the number correctly!") player_score += 1 round_winner = "player" break guesses_left -= 1 # if the player runs out of guesses, the computer wins if round_winner != "player": print(f"Sorry {name}, you ran out of guesses. The correct number was {secret_number}.") computer_score += 1 # show the results of the round print(f"Round {round_number} Results:") if round_winner == "player": print(f"{name} wins this round!") else: print(f"Computer wins this round!") print(f"Current Score: {name} {player_score} - Computer {computer_score}") print("-------------------------------------") round_number += 1 # if a player wins 2 rounds early, end the game if player_score == 2: print(f"\nCongratulations {name}, you have won 2 rounds! You win the game!") break elif computer_score == 2: print(f"Sorry {name}, the computer won 2 rounds. You lost the game!") break # Final results after all rounds if player_score > computer_score and player_score != 2: print(f"Game Over! Final Score: {name} {player_score} - Computer {computer_score}. {name} wins the game!") elif computer_score > player_score and computer_score != 2: print(f"Game Over! Final Score: {name} {player_score} - Computer {computer_score}. The computer wins the game!") else: print("Game Over!")