#------------------------------------------------- # Project: Pick up game # Standard: TE PUNGA - Programming Assessment # School: Tauranga Boys' College # Author: Ollie Cartwright # Date: March 2025 # Python: 3.11.9 #------------------------------------------------- MAX_CHIPS = 21 #sets the start amount of chips PlayerOneScore = 0 #sets the first players score to 0 PlayerTwoScore = 0#sets the second players score to 0 while True: #This block of code makes sure that the names are made of letters of the alphabet playerOneName = input("Player one's name: ") if playerOneName.isalpha(): while True: playerTwoName = input("Player two's name: ") if playerTwoName.isalpha(): break else: print("Please enter a valid name, try again.") break else: print("Please enter a valid name, try again.") while True: #makes sure that the number of rounds is between 1 - 5 try: rounds = int(input("How many rounds do you want to play? (Please choose between 1 and 5): ")) if rounds < 1 or rounds > 5: print("Please choose a number between 1 and 5") else: break except ValueError: print("You didn't even put a number in, how am I supposed to continue the game?") while rounds > 0: #This repeats everything in this loop until the rounds is equal to 0 chipsLeft = MAX_CHIPS#Resets the number of chips left while chipsLeft > 0: #While there is more then 0 chips left this loop repeats. print(f"\nThere are {chipsLeft} chips left.\n")#Prints how many chips there are. # Player 1's turn while True: try: if chipsLeft < 4: #If the chips left is less then 4 the code will make sure that the number of chips taken is valid chipsTaken = int(input(f"How many chips does {playerOneName} want to take? (please choose between 1 and {chipsLeft}): ")) else: chipsTaken = int(input(f"How many chips does {playerOneName} want to take? (please choose between 1 and 3): ")) if chipsTaken < 1 or chipsTaken > 3 or chipsTaken > chipsLeft: #makes sure that the input for chips taken is valid print(f"Please choose a valid number between 1 and {min(3, chipsLeft)}.") else:#If the input is valid then it brecks this loop. break except ValueError:#If the input isnt a number or valid then it says this. print("Please enter a valid number.") chipsLeft -= chipsTaken #takes the amount of chips taken away from the amount of chips left. if chipsLeft <= 0: #If the chips left is equal to or less than 0 then it adds a score to player one and displays the scores. PlayerOneScore += 1 print(f"{playerOneName}'s score: {PlayerOneScore}") print(f"{playerTwoName}'s score: {PlayerTwoScore}") break print(f"\nThere are {chipsLeft} chips left.\n") #Says the amount of chips left # Player 2's turn while True: try:#--------------This code asks how many chips player two wants to take and makes sure that the number is between 1 - 3. if chipsLeft < 4: chipsTaken = int(input(f"How many chips does {playerTwoName} want to take? (please choose between 1 and {chipsLeft}): ")) else: chipsTaken = int(input(f"How many chips does {playerTwoName} want to take? (please choose between 1 and 3): ")) if chipsTaken < 1 or chipsTaken > 3 or chipsTaken > chipsLeft: print(f"Please choose a valid number between 1 and {min(3, chipsLeft)}.")#This code prints the amount of chips you can take away if chips left is more then 3 it prints 3 and if its less then 3 then it prints that number. else: break except ValueError: print("Please enter a valid number.") chipsLeft -= chipsTaken #takes chips taken from chips left if chipsLeft <= 0: #if chips left is less or equal to 0 then it displays the score. PlayerTwoScore += 1 print(f"{playerOneName}'s score: {PlayerOneScore}") print(f"{playerTwoName}'s score: {PlayerTwoScore}") break rounds -= 1 #takes away one from the current number of rounds if PlayerOneScore == PlayerTwoScore: print("Tie! You both lose!") # Display final scores after all rounds print(f"\nFinal Scores:\n{playerOneName}: {PlayerOneScore}\n{playerTwoName}: {PlayerTwoScore}")#Prints the final scores