""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Ryman Song Date: 13/03/2025 Python: 3.5 ------------------------------------------------- This program plays a takeaway game. the players who are playing are asked to name themselves and input the amount of rounds they would like to play (between 1 and 5) and then the game starts This program asks the players to take 1-3 chips from a total of 21 chips. The player that wins the round is the one who takes the last chip from the pile leaving 0 chips remaining. ------------------------------------------------- """ #Setting up the game by setting the total number of chips #The player choices for taken chips are also set up here def get_choice(name, player): while True: try: choice = int(input(f"{name} (Player {player}), how many chips do you want to take (1-3)? ")) if choice < 1 or choice > 3: print("Invalid choice. You must take between 1 and 3 chips.") else: return choice except ValueError: print("Invalid input!") def play_round(name1, name2): MAX_CHIPS = 21 while MAX_CHIPS > 0: for player, name in [(1, name1), (2, name2)]: print(f"\nChips remaining: {MAX_CHIPS}") choice = get_choice(name, player) while choice > MAX_CHIPS: print("You cannot take more chips than are remaining.") choice = get_choice(name, player) MAX_CHIPS -= choice if MAX_CHIPS == 0: print(f"{name} took the last chip! {name} wins this round.") return player #Greets players and asks for their names and the amount of rounds they want to play #The string is to make sure the player can input a valid name, which has no numbers or special characters #The string also helps to make sure the player inputs a number between 1 and 5 for the rounds and makes sure there are no letters print("Welcome to the 21 Chips Game!") while True: name1 = str(input("Enter name for Player 1: ")) if name1.isalpha() == True: break else: print("Thats not allowed, try again") while True: name2 = str(input("Enter name for Player 2: ")) if name2.isalpha() == True: break else: print("Thats not allowed, try again") while True: try: rounds = int(input("How many rounds do you want to play? Between 1-5 ")) if rounds < 1 or rounds > 5: print("Please choose a number between 1 and 5") else: break except: print("This is not right try again") wins1 = 0 wins2 = 0 #Tells the players the current round and then prints the winner or loser for currentround in range(1, rounds + 1): print(f"\nRound {currentround}") loser = play_round(name1, name2) if loser == 1: wins1 += 1 else: wins2 += 1 print(f"Score: {name1} - {wins1} | {name2} - {wins2}") # Final score summary print("\nFinal Scores:") print(f"{name1}: {wins1} wins") print(f"{name2}: {wins2} wins") #End score that shows the winner if wins1 > wins2: print(f"{name1} is the overall winner!") elif wins2 > wins1: print(f"{name2} is the overall winner!") else: print("It's a tie!")