#-------------------------------------------------------------------------- # Name : 21 take away # Purpose : 11DGT # Author: Jasper Harvey # Created : 11/03/25 # Copyright : © Jasper Harvey #-------------------------------------------------------------------------- #import libraries import time import random #player names and introduction print("█▀█ ▄█   ▀▀█▀▀ █▀▀█ █ █ █▀▀   █▀▀█ █ █ █▀▀█ █ █   █▀▀▀ █▀▀█ █▀▄▀█ █▀▀ ") print(" ▄▀ █   █ █▄▄█ █▀▄ █▀▀   █▄▄█ █▄█▄█ █▄▄█ █▄▄█   █ ▀█ █▄▄█ █ ▀ █ █▀▀ ") print("█▄▄ ▄█▄   ▀ ▀ ▀ ▀ ▀ ▀▀▀   ▀ ▀ ▀ ▀ ▀ ▀ ▄▄▄█   ▀▀▀▀ ▀ ▀ ▀ ▀ ▀▀▀") time.sleep(1) print() while True: player_1=input("enter player ones name: ") if player_1.isalpha()==True: break else: print("that is not an acceptable name please try again.") while True: player_2=input("enter player two name: ") if player_2.isalpha()==True: break else: print("that is not an acceptable name please try again.") #intructions on how to play the game print() print("-------------------------------------------") print() print("You will start with 21 chips, each player will take turn taking from the chips.") time.sleep(1) print("You can take between 1-3 chips.") time.sleep(1) print("The player to take the last chip wins the round!") print() print("-------------------------------------------") print() time.sleep(1) #veribles chips=21 take_away=0 rounds=0 player_1_rounds=0 player_2_rounds=0 player_1_turn="y" player_2_turn="n" #amount of rounds played while True: try: rounds=int(input("enter amount of rounds youd like to play: ")) if rounds < 1 or rounds > 5: print("Please choose a number between 1 and 5.") else: break except: print("you didnt even put a number in bruh.") print() print("-------------------------------------------") print() #start of game loop------------------------------------------------------------------------------- while player_1_rounds < rounds or player_2_rounds < rounds: while chips != 0: #player 1's turn if player_1_turn == "y": while True: try: take_away=int(input(f"{player_1} enter the amout you would like to take away : ")) if take_away < 1 or take_away > 3: print("Please choose a number between 1 and 3.") else: break except: print("you didnt even put a number in bruh.") chips=chips-take_away print(f"there are {chips} chips left.") print() print("-------------------------------------------") print() player_1_turn="n" player_2_turn="y" break #breaks the while loop if some one won a round if chips == 0: break #player 2's turn if player_2_turn == "y": while True: try: take_away=int(input(f"{player_2} enter the amout would like to take away : ")) if take_away < 1 or take_away > 3: print("Please choose a number between 1 and 3.") else: break except: print("You didnt even put a number in bruh.") chips=chips-take_away print(f"there are {chips} chips left.") print() print("-------------------------------------------") print() player_2_turn="n" player_1_turn="y" break #breaks the while loop if some one won a round if chips == 0: break #checking to see if a player won a round if chips == 0 and player_1_turn=="n": player_1_rounds=player_1_rounds+1 print(f"Congrats {player_1} you won!") time.sleep(1) print(f"The score is now {player_1_rounds} - {player_2_rounds}!") time.sleep(1) chips=21 print() print("-------------------------------------------") print() elif chips == 0 and player_2_turn=="n": player_2_rounds=player_2_rounds+1 print(f"Congrats {player_2} you won!") time.sleep(1) print(f"The score is now {player_1_rounds} - {player_2_rounds}!") time.sleep(1) chips=21 print() print("-------------------------------------------") print() #breaks the code wehn a player has won if player_1_rounds == rounds or player_2_rounds == rounds: break #end of game winner text if player_1_rounds == rounds: winner=player_1 else: winner=player_2 print(f"congrats {winner} you won the game!!!") print(f"the final score was {player_1_rounds} - {player_2_rounds}") time.sleep(1) print("thank you for playing take away 21!") print() print("-------------------------------------------") print()