#------------------------------------------------- # Project: Take-Away Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Barnett Chhun # Date: 17/03/2025 # Python: 3.5 #------------------------------------------------- #Set Max Chips and Player Score MAX_CHIPS = 21 player_one_score = 0 player_two_score = 0 #Ask for Player One Name while True: player_one_name = input("Enter Player 1 name: ") if player_one_name.isalpha(): #Makes sure name can only have letter break else: print("Invalid name. Please enter letters only. Name cannot contain numbers, special characters or space.") #Ask for Player Two Name while True: player_two_name = input("Enter Player 2 name: ") if player_two_name.isalpha(): #Makes sure name can only have letter break else: print("Invalid name. Please enter letters only. Name cannot contain numbers, special characters or space.") #Ask for number of round while True: rounds = input("Enter the number of rounds (1-5): ") if rounds.isdigit() and 1 <= int(rounds) <= 5: #Makes sure rounds can only be an integer and has to be between 1-5 rounds = int(rounds) break else: print("Invalid input. Please enter a number between 1 and 5.") #Main game loop while rounds > 0: chips_left = MAX_CHIPS #Set Max Chips while chips_left > 0: print("Chips left:", chips_left) #Display amount of chips left #Player one turn while True: chips_taken = input(player_one_name + ", how many chips will you take? (1-3) ") #Ask player how many chips they're taking if chips_taken.isdigit() and 1 <= int(chips_taken) <= 3 and int(chips_taken) <= chips_left: #Makes sure it can only be an integer and has to be between 1-3 chips_taken = int(chips_taken) break else: print("Invalid choice. Choose between 1 and 3, or no more than the chips left:", chips_left) chips_left -= chips_taken if chips_left < 1: print(player_one_name, "has won the round") #Display winner of the round player_one_score += 1 break print("Chips left:", chips_left) #Player two turn while True: chips_taken = input(player_two_name + ", how many chips will you take? (1-3) ") #Ask player how many chips they're taking if chips_taken.isdigit() and 1 <= int(chips_taken) <= 3 and int(chips_taken) <= chips_left: #Makes sure it can only be an integer and has to be between 1-3 chips_taken = int(chips_taken) break else: print("Invalid choice. Choose between 1 and 3, or no more than the chips left:", chips_left) chips_left -= chips_taken if chips_left < 1: print(player_two_name, "has won the round") #Display winner of the round player_two_score += 1 break rounds -= 1 #Takes away one round print("Rounds left", rounds) #Display the rounds left to play #Display the overall winner of the game if player_one_score > player_two_score: print(player_one_name, "wins with", player_one_score, "rounds!") elif player_two_score > player_one_score: print(player_two_name, "wins with", player_two_score, "rounds!") else: print("It's a tie!")