""" -------------------------------------------------A Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: DEVAN JAMES YUILL Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ MAX_CHIPS = 21 PlayerOneScore = 0 PlayerTwoScore = 0 chipsLeft = 0 chipsTaken = 0 import time name1 = input("What Is Your Name, Player 1? ") name2 = input("What Is Your Name, Player 2? ") print("Welcome to the game,", name1, "and", name2) 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 between 1-5. I'm not coding more than that, my friend..") else: print(f"Great! You will now play {rounds} rounds.") break except ValueError: print("You didn't even enter a number, homeboy! How am I supposed to proceed? Think about that.") print("Game Starting...") time.sleep(2) # Game loop for round_num in range(1, rounds + 1): print(f"\nRound {round_num} Starts!") chipsLeft = MAX_CHIPS # Reset chips for each round # Keep the chip-taking logic inside this loop while chipsLeft > 0: print(f"\nChips Left: {chipsLeft}") # Player 1's turn print(f"{name1}, it's your turn. Choose 1 or 3 chips to take.") while True: try: chipsTaken = int(input("How many chips do you want to take? ")) if chipsTaken not in [1, 3]: print("You can only take 1 or 3 chips. Try again.") elif chipsTaken > chipsLeft: print(f"There are only {chipsLeft} chips left. Try taking that or fewer.") else: chipsLeft -= chipsTaken break except ValueError: print("Invalid input. Please enter 1 or 3.") # Check if the game is over after Player 1's turn if chipsLeft == 0: print(f"{name1} wins the round!") PlayerOneScore += 1 # Player 1 gets a point break # Player 2's turn print(f"{name2}, it's your turn. Choose 1 or 3 chips to take.") while True: try: chipsTaken = int(input("How many chips do you want to take? ")) if chipsTaken not in [1, 3]: print("You can only take 1 or 3 chips. Try again.") elif chipsTaken > chipsLeft: print(f"There are only {chipsLeft} chips left. Try taking that or fewer.") else: chipsLeft -= chipsTaken break except ValueError: print("Invalid input. Please enter 1 or 3.") # Check if the game is over after Player 2's turn if chipsLeft == 0: print(f"{name2} wins the round!") PlayerTwoScore += 1 # Player 2 gets a point break # After all rounds print("\nGame Over!") print(f"{name1} scored {PlayerOneScore} points.") print(f"{name2} scored {PlayerTwoScore} points.") if PlayerOneScore > PlayerTwoScore: print(f"{name1} wins the game!") elif PlayerTwoScore > PlayerOneScore: print(f"{name2} wins the game!") else: print("It's a tie!")