""" ------------------------------------------------- game: takeaway game school: tauranga boys college writer: alex sanita date: 21/03/2025 ------------------------------------------------- """ import time import random # constant variables MAX_CHIPS = 21 # variables player1_score = 0 player2_score = 0 chips = 0 chipstaken = 0 rounds_played = 0 # getting both names while True: player1 = str(input("player 1, enter your name?")) if player1.isalpha() == True: break else: print("that name wont work") while True: player2 = str(input("Player 2, what is your name?")) if player2.isalpha() == True: break else: print("that name wont work") # explains game to player print("welcome to the take away game", player1,"and", player2) time.sleep(0.76) print(f"------instructions------") time.sleep(0.76) print("Take a certain amount of chips(between 1 and 3). Player 1 will start then player 2 will follow") time.sleep(0.76) print("The person who takes the last chip wins the round") time.sleep(0.76) print("Who ever comes out with the highest score at the end of the maximum 5 rounds wins") time.sleep(0.76) print("if you don't follow the rules your turn will be skipped, no warning") time.sleep(0.76) print(f"good luck {player1}, and {player2}") # players pick amount of rounds they want to play while True: rounds = int(input("how many rounds do you want to play? 1-5 : ")) if rounds < 1 or rounds > 5: # if the user inputs a number above 5 or below 0 then it re-asks orignial question print("Please choose a number between 1 and 5") else: break # game loop while rounds > 0 : #sets the starting chips to max_chips(21) then displays the score and rounds then the amount of chips chipsleft = MAX_CHIPS print(f"{player1}'s score = ", player1_score, f"{player2}'s score = ", player2_score) print(f"Rounds - {rounds}") print("there are ", chipsleft,"chips left") print("-----------------------------------") while chipsleft > 0 : # starts the game with player 1 taking the first set of chips print(f"{player1} its your turn!") print("there are ", chipsleft,"chips left") chipstaken = int(input("do you want to take 1, 2, or 3 chips: ")) print("-----------------------------------") if chipstaken > 3 or chipstaken < 1: print("pick a number between 1 and 3") else: chipsleft -= chipstaken # if player has no chips what ever player took the chips wins and score gets update if chipsleft <= 0 : player1_score = player1_score + 1 print(f"{player1} wins the round") rounds = rounds - 1 break print(f"{player2} its your turn") print("there are ", chipsleft,"chips left") # player 2 code chipstaken = int(input("do you want to take 1, 2, or 3 chips: ")) print("-----------------------------------") if chipstaken > 3 or chipstaken < 1 : print("pick a number between 1 and 3") else: chipsleft -= chipstaken # if player has no chips what ever player took the chips wins and score gets updated if chipsleft <= 0 : player2_score = player2_score + 1 print(f"{player2} wins this round") rounds = rounds - 1 break # shows the final score and who won if rounds == 0 : print(f"{player1}'s score = ", player1_score, f"{player2}'s score = ", player2_score) if player1_score > player2_score : print(f"{player1} wins!") else: print(f"{player2} wins") if player1_score == player2_score : print(f"tie, play again")