""" -------------------------------------------------------------------------- Project : Guess The Number Purpose : 11DGT Author: Luke Jones Created : 11/03/24 Copyright : © Luke Jones 11/03/24 -------------------------------------------------------------------------- """ # --- Importing --- import random from time import sleep # --- Setup Variables --- reset_guesses = 0 rounds = 3 user_score = 0 AI_score = 0 game_end = False round = 1 # --- Game Introduction --- print("Welcome to Guess the Number") while True: name = str(input("What is your name? ")) if name.isalpha() == True: break else: print("Enter a real name!") print("Hello {}, in this game you will be trying to guess a number between 1-1000.".format(name)) sleep(1) print("You will get 10 guesses per round, and there will be 3 rounds.") sleep(1) # --- Function for when the game ends --- def game_scores(): print("") print("The game has ended.") print("") print("Your final score: {}".format(user_score)) print("AI final score: {}".format(AI_score)) if AI_score > user_score: print("AI won!") else: print("You won!") # --- Function to check when the game should end --- def game_end_check(): global game_end global round if AI_score == 2 or user_score == 2: game_end = True else: round += 1 # --- Game Loop --- while game_end == False: number = random.randint(1, 1000) guesses = reset_guesses print(" ") print("Current round: {}".format(round)) print("Your score: {}".format(user_score)) print("AI Score: {}".format(AI_score)) print(" ") # While loop for guessing the number while guesses < 10: guess = int(input("Input your guess: ")) if guess == number: user_score += 1 game_end_check() print(" ") print("You got the number and win the round!") guesses = 10 elif guesses == 9: AI_score += 1 game_end_check() print(" ") print("You failed to get the number and lose the round!") guesses = 10 else: if guess > number: print("Try Lower!") else: print("Try Higher!") guesses += 1 # --- Runs the end of game function after the while loop ends --- game_scores()