""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Eli Blandford Date: 05/03/2025 Python: 3.5 ------------------------------------------------- """ #this is to add a random number for the number the progam has and what the player is guessing #also time just to give breaks in the code import time import random #introducing the game print("this is the guessing game") print("") #this is to get the players name so we can use it in the code. while True: name = input("what is your name? ") if name.isalpha()== True: print("thank you "+ name) break else: print("please use letters and letters only") #this is to reset the score after each game start_CPU_score = 0 start_player_score = 0 start_guesses = 10 round=0 start_player_number = 0 player_number = 0 CPU_number = 0 player_score = start_player_score CPU_score = start_CPU_score play_again= "y" #this is the start of the game print("we can now begin "+ name + " I'm thinking off a number between 1-1000. you have 10 guesses") time.sleep(2) #this is the actual code that makes the game run while play_again=="y": player_score = start_player_score CPU_score = start_CPU_score CPU_number = random.randint(1,1000) guesses = start_guesses while player_number != CPU_number : player_number = int(input("what do you think the number is? ")) time.sleep(1) #this is to check if the player has guessed the number and give you a point if player_number == CPU_number: print("") print("You got it!") time.sleep(2) player_score = player_score + 1 CPU_score = CPU_score + 0 round = round + 1 print("CPU_score is {}".format(CPU_score)) print("") print("player score is {}".format(player_score)) CPU_number= random.randint(1,1000) guesses =start_guesses #this is to check if the number is higher than the actual number and tell him it is lower elif player_number > CPU_number: player_number = start_player_number print("lower! ") print("") guesses = guesses - 1 print("you have {} guesses left".format(guesses)) if guesses ==0: print("you lost the number is {}".format(CPU_number)) CPU_score = CPU_score + 1 player_score = player_score + 0 print("CPU_score is {}".format(CPU_score)) print("") print("player score is {}".format(player_score)) CPU_number= random.randint(1,1000) guesses =start_guesses player_number = start_player_number else: print("higher! ") print("") guesses = guesses - 1 print("you have {} guesses left".format(guesses)) if guesses ==0: print("you lost the number is {}".format(CPU_number)) CPU_score = CPU_score + 1 player_score = player_score + 0 print("CPU_score is {}".format(CPU_score)) print("") print("player score is {}".format(player_score)) CPU_number= random.randint(1,1000) guesses =start_guesses player_number = start_player_number if player_score == 2: print ("you have won! you are the best player in the world") time.sleep(2) print("") print("") print("the score was {} {} to CPU {}".format(name,player_score,CPU_score)) play_again=input("would you like to play again? [y]es or [n]o? ") if play_again != "y": break else: player_score = start_player_score CPU_score = start_CPU_score CPU_number = random.randint(1,10) guesses = start_guesses elif CPU_score == 2: print ("you have lost to the all powerful AI! you suck") print("") print("the score was CPU {} to {} {}".format(CPU_score,name,player_score)) time.sleep(2) print("") play_again=input("would you like to play again? [y]es or [n]o? ") if play_again != "y": break else: player_score = start_player_score CPU_score = start_CPU_score CPU_number = random.randint(1,10) guesses = start_guesses print("") print("thank you for playing my game")