#------------------------------------------------- # Project: Take-Away Game # Standard: TE PUNGA - Programming Assessment # School: Tauranga Boys' College # Author: Travis Lammas # Date: March 25th 2024 # Python: 3.5 #------------------------------------------------- import time #introduces all variables player1 = input("Enter Player 1: ") time.sleep(1) player2 = input("Enter player 2: ") time.sleep(1) rounds = int(input("Enter number of rounds: ")) chipstaken = 0 p1score = 0 p2score = 0 roundsplayed= 0 maxchips = 21 currentplayer = player1 #starts loop while roundsplayed != rounds: currentplayer = player1 chips = maxchips roundsplayed += 1 time.sleep(1) print("round", roundsplayed) time.sleep(1) print("scores:", player1, "has", p1score, "points and", player2, "has", p2score, "points") time.sleep(1) print(currentplayer + "'s turn") time.sleep(1) #checks if there are chips left while chips > 0: #player1 turn if currentplayer == player1: print("There are", chips, "left") time.sleep(1) chipstaken = int(input("How many chips would you like to take away " + currentplayer + "? 1, 2 or 3? ")) time.sleep(1) #makes sure p1's choice was between 1 and 3 if chipstaken >3 or chipstaken <1 : while True: print("That is not between 1 and 3") time.sleep(1) print("pick again") time.sleep(1) chipstaken = int(input("How many chips would you like to take away " + currentplayer +"? 1, 2 or 3? ")) if chipstaken >3 or chipstaken <1 : True else: break chips -= chipstaken currentplayer = player2 #takes away chips else: chips -= chipstaken currentplayer = player2 #player2 turn elif currentplayer == player2: time.sleep(1) print("There are", chips, "left") time.sleep(1) chipstaken = int(input("How many chips would you like to take away " + currentplayer +"? 1, 2 or 3? ")) time.sleep(1) #makes sure p2's choice was between 1 and 3 if chipstaken >3 or chipstaken <1 : while True: print("That is not between 1 and 3") time.sleep(1) print("pick again") time.sleep(1) chipstaken = int(input("How many chips would you like to take away " + currentplayer +"? 1, 2 or 3? ")) if chipstaken >3 or chipstaken <1 : True else: break chips -= chipstaken currentplayer = player1 #takes chips away else: chips -= chipstaken currentplayer = player1 if chips <= 0: #if player 2 won if currentplayer == player1: currentplayer = player2 print(currentplayer, "takes this round") time.sleep(1) #if player 1 won elif currentplayer == player2: currentplayer = player1 print(currentplayer, "takes this round") time.sleep(1) #adds score if currentplayer == player1: p1score += 1 elif currentplayer == player2: p2score += 1 #the end if roundsplayed == rounds: print("Final Scores:", player1, "scored", p1score, "points and", player2, "scored", p2score) time.sleep(1) if p1score == p2score: print("Its a draw!") elif p1score > p2score: print("Well done", player1) elif p2score > p1score: print("Well done", player2)