""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Aarav Sharma Date: 18/02/25 Python: 3.5 ------------------------------------------------- """ import time import random # variables player_1_score = 0 player_2_score = 0 rounds_played = 0 MAX_CHIPS = 21 print("\nHello there!") time.sleep(1) print("\nWelcome to the game!") time.sleep(1) print("in this game, 2 players will take turns taking chips") time.sleep(1) print("The maximum amount of chips you can take is 3 and the mimimum is 1") time.sleep(2) print("The aim of the game is to try and be player who takes the last chip/chips") time.sleep(1) print("Let's begin!") # Asking the player for their names while True: print() name1 = input("What is player1's name? ") if name1.isalpha(): # Checks if input is a proper name break else: print("That name is not acceptable, please add your real name ") while True: name2 = input("What is player2's name? ") if name2.isalpha(): # same thing as name1 break else: print("That name is not acceptable, please add your real name ") # Asking the numbe of rounds between 1-5 while True: try: print("\nHello", name1, "and", name2) rounds = int(input("How many rounds do you want to play? 1-5: ")) if rounds < 1 or rounds > 5: #Making sure the user picks number between 1-5 print("choose a number between 1-5.") else: break except ValueError: print("Please try again, maybe put just a number this time.") # Start of the game loop while rounds > 0: chips_left = MAX_CHIPS print("\nRounds left:", rounds) while chips_left > 0: #ONly playes if the chips are more then 0 # Player 1's turn to pick print("Chips left:", chips_left) while True: try: print(name1) chips_taken = int(input("choose an amount of chips to take (1-3): ")) #the int input puts the stroig into a integer if 0 < chips_taken <4: #makes sure that the player cant take more than 3 ans less than 1 chips chips_left -= chips_taken break else: print("PLwase take between 1 and 3 chips") except ValueError: #if it isnt a number print("Please try again, maybe put just a number this time.") if chips_left == 0: print(name1, "wins!") player_1_score += 1 print(name1, "score is",player_1_score, "and", name2, "score is", player_2_score) break # Player 2's turn print("Chips left:" ,chips_left) while True: try: print(name2) chips_taken = int(input("choose an amount of chips to take (1-3): ")) if 0 < chips_taken <4: chips_left -= chips_taken break else: print("PLwase take between 1 and 3 chips") except ValueError: #if the player enters something that isnt a number print("please enter a proper number.") if chips_left == 0: #This code if when thr amount if chips reaches 0 and then the game either ends or goes to anothor round print(name2, "\nwins this round!") player_2_score += 1 #Adds 1 to score after each round print(name1, "score is",player_1_score, "and", name2, "score is", player_2_score) break rounds -= 1 # takes away 1 form each Rounds # Shows the scores after evry gamw print("\nGame Over!") if player_1_score > player_2_score: print(name1, "wins the game!") elif player_2_score > player_1_score: print(name2, "wins the game!") else: #Displays who wins at the end print("Its a tie you both win")