""" ------------------------------------------------- Project: TE PUNGA - Programming Assessment 10% Standard: TE PUNGA - Programming Assessment School: Tauranga Boys' College Author: Logan Baldwin Date: March 2025 Python: 3.7.4 ------------------------------------------------- """ #Import what we need import random #The Variables MAXCHIPS = 21 chipsLeft = 0 chipsTaken = 0 player2score = 0 player1score = 0 rounds_played = 0 #Making sure the name is letters and has no spaces while True: name1 = input("What is the first player's name? ") if name1.isalpha(): break #Stops the loop else: print("That isn't a valid name please re try.") #Making sure the name is letters and has no spaces while True: name2 = input("What is the second person's name? ") if name2.isalpha(): break #Stops the loop else: print("That isn't a valid name please re try.") #How many rounds the user would wnat to play while True: try: rounds = int(input("How many rounds would you like to play?")) if rounds < 1 or rounds > 5: #If the player types a number below 1 or above 5, it will ask it again. print("Please make sure the number is between 1 and 5 ") else: break #End the loop except: #If the user is a idiot and dosen't even put a number, it will ask again print("Are you silly? Enter a number... ") print("Hi and goodluck!") #Greeting #Main game loop while rounds > 0: chipsLeft = MAXCHIPS #The chips in the game is always re set to 21 after a round # Loop until the round ends (chips run out) while chipsLeft > 0: # Player 1 turn print(f"\n{name1}'s turn. Chips remaining: {chipsLeft}") correctAmount = False while not correctAmount: #Making sure that the try: chipsTaken = int(input(f"{name1}, pick how many chips to take, (1-3) ")) if chipsTaken < 1 or chipsTaken > 3: print("Invalid move. You must take between 1 and 3 chips.") elif chipsTaken > chipsLeft: print(f"Not enough chips left! You can only take up to {chipsLeft} chip(s).") else: correctAmount = True except ValueError: print("Please enter a valid number.") chipsLeft -= chipsTaken #Minus the taken chips from the total if chipsLeft <= 0: player1score += 1 print(f"\n{name1} wins round this round!") rounds -= 1 rounds_played += 1 print(f"--- ROUND {rounds_played}! ---") print(f"\n- Current Scores! {name1}, {player1score}, {name2}, {player2score}!") break # Player 2 turn print(f"\n{name2}'s turn. Chips remaining: {chipsLeft}") correctAmount = False while not correctAmount: try: chipsTaken = int(input(f"{name2}, pick how many chips to take (1-3): ")) if chipsTaken < 1 or chipsTaken > 3: print("Invalid move. You must take between 1 and 3 chips.") elif chipsTaken > chipsLeft: print(f"Not enough chips left! You can only take up to {chipsLeft} chip(s).") else: correctAmount = True except ValueError: print("Please enter a valid number.") chipsLeft -= chipsTaken if chipsLeft <= 0: player2score += 1 print(f"\n{name2} wins round this round!") rounds -= 1 rounds_played += 1 print(f"--- ROUND {rounds_played}! ---") print(f"\n- Current Scores! {name1}, {player1score}, {name2}, {player2score}!") break #End of the game! print("\n--- GAME OVER! ---") print(f"\nFinal Scores, {name1}, {player1score}, {name2}, {player2score}") if player1score > player2score: print(f"{name1} wins the game!") elif player2score > player1score: print(f"{name2} wins the game!") else: print("It's a tie trash cans!")