#------------------------------------------------ # Project: Guessing Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys College # Author: Shay McDonald # Date: 15/03/2024 # Python: 3.5 #------------------------------------------------ # Sequences import random import time while True: play = input("Would you like to play? (y/n): ") if play.lower() != "y": break # While the play variable input is = to lowercase y, if not break print("") print("How To Play!") print("") time.sleep(0.5) print("- Guess A Number Between 1 & 1000") print("") time.sleep(0.5) print("- The Computer Will Tell You Higher Or Lower") print("") time.sleep(0.5) print("- You Have 10 Tries To Guess The Right Answer") time.sleep(0.5) print("") print("- First To 3 Wins!") print("") name = input("What is your name?: ") print("") time.sleep(1) def Hello_Name(name) : # Use of function print("Hello " + name + " Welcome To Number Guess!") Hello_Name(name) def Name_Final_Score(name) : print(name, "Wins!") # This is where the player tells the game their name def setup(): global player_score global computer_score global round_number player_score = 0 computer_score = 0 round_number = 1 setup() # Settings variables while player_score < 3 and computer_score < 3: guess_number = 1 print("") print("- Round", round_number, "Has Started") # While player and computer scores are less than 3 continue with loop computer_number = random.randint(1, 1000) # Selecting random number while guess_number <= 10: # While you have guesses remaining run loop print("- Guess", guess_number) print("") while True: try: guess = int(input("Guess A Number: ")) if guess < 1 or guess > 1000 : print("Please choose a number between 1 and 1000") else: break except: print("Please enter a valid number") # This code is making it so that the players guess has to be between 1 and 1000 otherwise is asks to reguess guess_number += 1 # When a guess is used the guess number = +1 if guess == computer_number: print("Correct") print("") player_score += 1 break # If player guess is = to computer number player socre = +1 and loop restarts elif guess < computer_number: print("The Number Is HIGHER") print("") # If player guess is less than the computer number it tells the player that the number is higher elif guess > computer_number: print("The Number Is LOWER") print("") # If player guess is higher than the computer number it tells the player that the number is lower else: print("Out of guesses! The correct number was:", computer_number) computer_score += 1 # If you are out of guess the loop ends and computer score goes up by 1 print("") print("Round", round_number, "Complete") print("") print("Player Score =", player_score) print("Computer Score =", computer_score) print("") round_number += 1 # At the end of every round the prints showing the scores and the round number print("GAME OVER") if player_score == 3: print(name, "Wins!") else: print("Computer Wins!") # When either player or computer score is equal to 3 it checks if it was the player who won if not it awards the computer the win print("") print("Final Score") print("") print("Player Score =", player_score) print("Computer Score =", computer_score) # This shows at the end of the game once all the loops have broke showing the final score and the game winner