""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: YOUR FULL NAME Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ import random MAX_CHIPS = 21 playerOneScore = 0 playerTwoScore = 0 chipsLeft = 0 # get player names and round count player1name = input("Enter player one name: ") player2name = input("Enter player two 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 turn print(f"\nchips left: {chipsleft}") validInput = False while not validInput: # Loop until player inputs a valid number of chips try: player1Chips = int(input(f"{player1name},choose the number of chips to take: ")) if player1Chips > chipsLeft: print(F"{player1name}, you cannot take more chips than what's left.") else: validInput = True chipsLeft -= player1Chips except ValueError: print("Please enter a valid number. ") if chipsLeft <= 0: playerpnescore += 1 print(f"{player1name} win this round!") break # player one win, 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"{player2name}, choose the number of chips to take: ")) if playerTwoChips > chipsleft: print(f"{player2name}, you cannot take more chips that what is left.") else: validInput = True ChipsLeft -= playerTwoChips except ValueError: print ("Please enter a valid number.") if chipsleft <= 0: playerTwoScore += 1 print(f"{player1name} 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"{player2name}, choose the number of chips to take: ")) if playerTwoChips > chipsLeft: print(f"{player2name}, 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"{player2name} 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"{player1name} wins with a score of {playerOneScore}!") elif playerTwoScore > playerOneScore: print(f"{player2name} wins with a score of {playerTwoScore}!") else: print("It's a tie!")