""" ------------------------------------------------- Project: Chips Game Standard: Te Punga - Programming Assement School: Tauranga Boys' College Author: Prabvir Shoker Date: 21/03/25 Python: 3.5 ------------------------------------------------- """ import random max_chips=21 chips_left=0 chips_taken=0 player=0 player_1_score=0 player_2_score=0 play_again= "y" #SEttingup the players usernames while True: player_1 = input("What is your name player 1? ") if player_1.isalpha()==True: print() print("Hello! ", player_1) print() break else: print() print("That name is not valid player 1.") print() while True: player_2 = input("And what is your name player 2? ") if player_2.isalpha()==True: print() print("Hello", player_1 ,"and" , player_2) print() break else: print() print("That name is not valid player 2.") print() #making the option to choose or randomize the rounds while True: rounds=input("do you want to choose your rounds or just a random amount? please pick: choose or random ") if rounds.isalpha()==False: print("please words not numbers") else: if rounds== "choose" or rounds == "Choose": try: round_num= int(input("pick between 1 - 5 rounds ")) if round_num <1 or round_num > 5: print("choose a number between 1 and 5 ") else: print("you will be playing {} rounds".format(round_num)) break except: print("please pick a number") break elif rounds == "random" or rounds == "Random": round_num=random.randint(1,5) print("you will play {} rounds".format(round_num)) break else: print("please pick choose or random") #the code for the game to actually work while play_again== "y": chips_left=max_chips player = random.randint (1,2) while round_num != 0: try: if player == 1: print("There is 21 chips") chips_taken = int(input(" {} How many chips would you like to take? ".format(player_1))) print("") if chips_taken < 1 or chips_taken > 3: print("Please choose between number 1 and 3. ") else: chips_left = chips_left - chips_taken print ("you have took {} chips and now there is {} chips left. ".format(chips_taken,chips_left)) player = player - 1 if chips_left < 1: print("{} took the last chip, congrats you won!".format(player_1)) player_1_score = player_1_score + 1 player_2_score = player_2_score + 0 round_num = round_num - 1 print("The score is now player 1 with {}, and player 2 with {}".format(player_1_score,player_2_score)) chips_left=max_chips else: try: chips_taken = int(input(" {} How many chips would you like to take? ".format(player_2))) print("") if chips_taken < 1 or chips_taken > 3: print("Please choose between number 1 and 3. ") else: chips_left = chips_left - chips_taken print("You took {} chips and there is now {} chips left. ".format(chips_taken,chips_left)) player = player - 1 if chips_left < 1: print("{} took the last chip, you won!".format(player_2)) player_1_score = player_1_score + 0 player_2_score = player_2_score + 1 round_num = round_num - 1 print("The score is now player 1 with {}, and player 2 with {}".format(player_2_score,player_1_score)) chips_left=max_chips except: print("Please choose between 1 and 3") except: print("Please choose between 1 and 3") if round_num < 1: print("GAME OVER. The final scores are {} and {}".format(player_1_score,player_2_score)) if player_1_score < player_2_score: print("The winner is {}!!!".format(player_2)) play_again = input("Would you like to play again? [y]es or [n]o? ") if play_again != "y": break elif player_1_score == player_2_score: print("Looks like its a draw between you guys, no one wins") play_again = input("Would you like to play again? [y]es or [n]o? ") if play_again != "y": break else: print("The winner is {}!!!".format(player_1)) play_again = input("Would you like to play again [y]es or [n]o? ") if play_again != "y": break print("Thank you {} and {} for playing my game!".format(player_1,player_2))