#------------------------------------------------- # Project: NBG # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: XANDER MAURI # Date: THE DATE YOU COMPLETED THE CODE # Python: 3.5 #------------------------------------------------- # Importing the required modules import random import time # Setting variables guesses=10 rounds=3 user_score=0 computer_score=0 total_rounds=3 # Showing game title print("\nGTN - Guess The Number") # Ask player for their name player_name = input("\nPlease enter your name:\t") # Display welcome message with player's name print(f"\nWelcome to GTN, {player_name}!") time.sleep(1.5) print("Let's play a game of guessing numbers, and me, the AI, as your opponent.") time.sleep(2) print("In this game, it's best out of 3 rounds, you will have to guess a number between 1 and 1000.") time.sleep(1.5) print("You will only have ten guesses each round.Good Luck, You're Gonna Need It.") time.sleep(2) print("Failed ttoo play file:0000000000000023546EVILLAUGH.") time.sleep(1) print("Due to inability to understand human emotion).\t") # Start of rounds loop while rounds <= 3: print(f"\nWelcome to Round {round}!\n\n") # Generate a random number number = random.randint(1, 1000) round_won = False # Telling player the number of guesses used print(f"You have {guesses} guesses left") # Starting the guessing process while guesses > 0 and not round_won: try: # Checking if user entered a number or not user_number = int(input("\nEnter your next guess:\t")) # Decrementing the number of remaining guesses guesses -=1 # Telling player that he won if user_number == number : user_score +=1 round_won=True # If user if user_number < number : print("Your guess is too low.\n") print(f"\nYou have {guesses} guesses left\t") elif user_number > number : print("Your guess is too high.\n") print(f"\nYou have {guesses} guesses left\t") # If none of the above conditions were met then it must be equal so we set the variable "round_won" as True and continue except ValueError: print("Invalid input.\nPlease enter a valid number.") else: continue # Seeing if Ai Won or User Won if not round_won: rounds-=1 computer_score+=1 if computer_score == 2: print("The AI is one round away from winning. You better hurry up!") print(f"User Score: {user_score},\nAI Score: {computer_score}") else: user_score+=1 rounds-=1 print("\nCongratulations!\nYou have won the game!") print(f"User Score: {user_score},\nAI Score: {computer_score}") break if round_won == True : user_score+=1 rounds-=1 if user_score == 1: print("Great job! You won this round!, But The game is not over yet.") print(f"User Score: {user_score},\nAI Score: {computer_score}") elif user_score == 2: print("Wow, you are on fire! Keep it up and you will be ahead in no time.") print(f"User Score: {user_score},\nAI Score: {computer_score}") # displaying final scores print(f"The final score is {user_score} for {player_name} and {computer_score} for the AI.") print ("Thanks for playing!\nSee you again soon!")