""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Paul gonzale # Date: 17/03.2025 Python: 3.5 ------------------------------------------------- """ MAX_CHIPS = 21 playerOneScore = 0 playerTwoScore = 0 chipsLeft = 0 # Get player names and rounds count playerOneName = input("Enter Player One's name: ") playerTwoName = input("Enter Player Two's name: ") rounds = int(input("Enter the number of rounds: ")) # Game Logic while rounds > 0: chipsLeft = MAX_CHIPS # Reset the number of chips for each round while chipsLeft > 0: # Player One's turn print(f"\nChips Left: {chipsLeft}") validInput = False while not validInput: # Loop until player inputs a valid number of chips try: playerOneChips = int(input(f"{playerOneName}, choose the number of chips to take: ")) if playerOneChips > chipsLeft: print(f"{playerOneName}, you cannot take more chips than what's left.") else: validInput = True chipsLeft -= playerOneChips except ValueError: print("Please enter a valid number.") if chipsLeft <= 0: playerOneScore += 1 print(f"{playerOneName} wins this round!") break # Player One wins, exit inner loop # Player Two's turn print(f"\nChips Left: {chipsLeft}") # validInput = False while not validInput: # Loop until player inputs a valid number of chips try: playerTwoChips = int(input(f"{playerTwoName}, choose the number of chips to take: ")) if playerTwoChips > chipsLeft: print(f"{playerTwoName}, you cannot take more chips than what's left.") else: validInput = True chipsLeft -= playerTwoChips except ValueError: print("Please enter a valid number.") if chipsLeft <= 0: playerTwoScore += 1 print(f"{playerTwoName} wins this round!") break # Player Two wins, exit inner loop rounds -= 1 # One round has been completed # Determine the winner print("\nGame Over!") if playerOneScore > playerTwoScore: print(f"{playerOneName} wins with a score of {playerOneScore}!") elif playerTwoScore > playerOneScore: print(f"{playerTwoName} wins with a score of {playerTwoScore}!") else: print("It's a tie!")