#------------------------------------------------- # Project: Te Punga 10% Assessment # Standard: TE PUNGA - Programming Assessment # School: Tauranga Boys' College # Author: Thomas Brighouse # Date: 18.03.24 # Python: 3.7.4 #------------------------------------------------- import time def best_score(score1, score2, nam1, nam2): if score1 > score2: return nam1 elif score2 > score1: return nam2 else: return "It's a tie" # Initial setup print("Welcome to the game") name1 = input("What is your name player 1? Please just use letters: ") name2 = input("What is your name Player 2? Please just use letters: ") # Number of rounds amount_rounds = int(input("How many rounds you wish to play (up to 5): ")) while amount_rounds > 5: print("Please pick a number that's 5 or less.") amount_rounds = int(input("How many rounds you wish to play? ")) print("Names are in, let's get onto the rules") # Game initialization chips_remaining = 21 score1 = 0 score2 = 0 player = name1 # Game rules print("Welcome to the game") time.sleep(1.5) print("You start with 21 chips the one who has the most chips at the end wins") time.sleep(1.5) print("You can only take 3 chips max at once") time.sleep(1.5) print("You will play the number of rounds you have put in") time.sleep(1.5) print("Let's see who wins at the end\n") time.sleep(1.5) print("Best of luck!") # Main game loop for round_on in range(1, amount_rounds + 1): chips = chips_remaining print(f"Round {round_on} out of {amount_rounds}, starting with {chips} chips.") while chips > 0: print(f"{player}'s turn. There are {chips} chips remaining.") pick = int(input(f"{player}, how many chips do you wish to pick (1-3)? ")) # If they chose chips over 3 while pick < 1 or pick > 3: print("Please pick a number between 1 and 3.") pick = int(input(f"{player}, how many chips do you wish to pick (1-3)? ")) # Update scores and switch players if player == name1: score1 += pick player = name2 else: score2 += pick player = name1 chips -= pick if chips <= 0: print(f"Round {round_on} ends.") break # Determine the winner or declare a tie based on chip counts if score1 > score2: winner = name1 elif score2 > score1: winner = name2 else: winner = "It's a tie" # Shows the score + Winner print("The game has ended") print(f"{name1} got {score1} chips") print(f"{name2} got {score2} chips") print(f"The winner is {winner}")