""" ------------------------------------------------- Project: Pick-Up Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Caleb Green Date: 17/03/2025 Python: 3.5 ------------------------------------------------- """ # Import time for taking breaks in the code import time # Max chips allowed in a round MAX_CHIPS = 21 time.sleep(1) # Get player 1's name while True: player1 = input("Player 1, what is your name? ") if player1.isalpha(): # Check if name has only letters break print("Invalid name, try again.") # Ask again if invalid time.sleep(1) # Get player 2's name while True: player2 = input("Player 2, what is your name? ") if player2.isalpha(): # Check if name has only letters break print("Invalid name, try again.") # Ask again if invalid time.sleep(1) # Get number of rounds (1-5) while True: try: rounds = int(input("How many rounds do you want to play? (1-5): ")) # Get users answer if 1 <= rounds <= 5: # Check if it's between 1 and 5 break print("Choose a number between 1 and 5.") # If player puts in a number too high or too low except ValueError: print("That's not a number, try again.") # If player puts in something else other than a number # Set scores to zero for both players player1score = 0 player2score = 0 # Main game loop - runs for the chosen number of rounds while rounds > 0: chips_left = MAX_CHIPS # Reset chips at start of each round print("New Round!") # Indicate start of round while chips_left > 0: # Loop until all chips are taken print(f"Chips left = {chips_left}") # Show remaining chips # Player 1's turn while True: try: chips_taken = int(input(f"{player1}, take 1-3 chips: ")) # Ask player how many chips if 1 <= chips_taken <= 3 and chips_taken <= chips_left: # Ensure valid number of chips break print("Choose between 1 and 3 chips.") # Error message for if input too high or too low except ValueError: print("Enter a number.") # Error message for non number input chips_left -= chips_taken # Subtract taken chips if chips_left == 0: # Check if player 1 won player1score += 1 # Increase Player 1's score print(f"{player1} wins this round!") # Announce winner break # End round # Continue to player 2 turn if not a win print(f"Chips left = {chips_left}") # Show updated chip count # Player 2's turn while True: try: chips_taken = int(input(f"{player2}, take 1-3 chips: ")) # Ask player how many chips if 1 <= chips_taken <= 3 and chips_taken <= chips_left: # Ensure valid number of chips break print("Choose between 1 and 3 chips or don't under more chips then there are left.") # # Error message for if input too high or too low except ValueError: print("Enter a number.") # Error message for non number input chips_left -= chips_taken # Subtract taken chips if chips_left == 0: # Check if player 2 won player2score += 1 # Increase Player 2's score print(f"{player2} wins this round!") # Announce winner break # End round # If not a win, repeat loop rounds -= 1 # Decrease remaining rounds print("Round Over!") # Indicate end of round # Show final scores time.sleep(1) print("Final Scores:") print(f"{player1}: {player1score} wins") # Indicate how many wins each player has print(f"{player2}: {player2score} wins") print() # Announce overall game winner time.sleep(1) if player1score > player2score: print(f"{player1} wins the game!") # Player 1 wins elif player1score < player2score: print(f"{player2} wins the game!") # Player 2 wins else: print("It's a tie!") # Game is tied