#------------------------------------------------- # Project: 10% assigment # Standard: TE PUNGA - Programming Assessment # School: Tauranga Boys' College # Author: Liam Briscoe # Date: 18/03/24 # Python: 3.7.4 #------------------------------------------------- import time #imports time for when the rules are explained #intialisng the game by resetting all the variables amount_rounds = 0 round_on = 1 chips_remaining = 21 score1 = 0 score2 = 0 pick = 0 win = 0 print("Welcome to the game") #Only allows play names with only letters no numbers or special charictors for the players name while True : nam1 = str(input("What is your name player 1? ")) if nam1.isalpha() == True : break else : print("That is a incorrect name please use only letters") #Only allows play names with only letters no numbers or special charictors for the players name while True : nam2 = str(input("What is your name Player 2? ")) if nam2.isalpha() == True : break else : print("Please choose a name with only letters") #sets us who the first player will be for the game player = nam1 #The player picks how many rounds they wish to play rounds_left = int( input("How many rounds you wish to play? " )) #Makes the player pick a amount of rounds that is five or less if they picked more then five while rounds_left > 5 : if rounds_left > 5 : print("Please Pick a number thats 5 or less ") rounds_left = int( input("How many rounds you wish to play? ")) if rounds_left < 6 : break chips = chips_remaining #prints out the game rules for the player to understand print("Welcome to the game") time.sleep(1)#adds a intervule so it looks better and easier to read print("You start with 21 chips") time.sleep(1) print("The one who takes the last chip wins") time.sleep(1) print("You may only take 3 chips max at once") time.sleep(1) print("You will play the amount of rounds you have specified") time.sleep(1) print("When you have finished the amount of rrounds you want to play we will see who won") time.sleep(1) #Loops the gamr while the amount of games played is less then the amount the player wants while rounds_left > 0 : print("You have", rounds_left, "rounds left") chips = 21 chips_remaining = 21 if rounds_left == 0 : break round_go = "y" #The ggame loop if where the player picks how much chips they wish to pick while chips_remaining > 1 : print("There is only", chips, "chip/s left") #Allows the player to pick how much chips they want to pick prompt = f"{player} please pick how much you wish to pick " pick = int( input(prompt)) #makes the player keep picking numbers until they pick 3 or less while pick > 3 : print("please pick a number that is equal to or less then 3") pick = int( input(prompt)) if pick <= 3 : break #if the player picks to high then makes the other person win if chips == 2 and pick > 2 : print("You picked to high and lose this round") if player == nam1 : player = nam2 break else : player = nam1 break #if the player picks to high then makes the other person win if chips == 1 and pick > 1 : print("You picked to high and lose this round") if player == nam1 : player = nam2 break else : player = nam1 break #takes away the amount of chips they picked from the total chips left else : chips = chips - pick #changes the player whos playing if player == nam1: if chips <1 : score1 += 1 player = nam2 #changes the player whos playing else: if chips <1 : score2 += 1 player = nam1 #breaks the loop if there is 0 chips left if chips <= 0: print(f"Round {round_on} ends.") rounds_left -= 1 break #Finds out which of the playes has the most chips and returns the player with the highest amount of chips def best_score(score1, score2, nam1, nam2): if score1 > score2: return nam1 elif score2 > score1: return nam2 else: return "It's a draw" #puts the result of best_score into a variable result = best_score(score1, score2, nam1, nam2) #Prints out the result of the game print("The game has ended") print(nam1, "got", score1, "win") print(nam2, "got", score2, "win") print("So the winner is", result)