#------------------------------------------------- # Project: Pick up game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Lexus Sroiparp # Date: March 14th 2025 # Python: 3.5 #------------------------------------------------- # Constants MAX_CHIPS = 21 # reset chips left to max chip at every round # Variables score_1 = 0 # player 1 score score_2 = 0 # player 2 score chips_left = 0 # how many chips are left chips_taken = 0 # change later when player chooses how many to take # Get player names def get_player_name(player_num): # Function to reuse the code instead of repeating it so it cleaner while True: #Checks for valid name so no numbers and stuff name = input("What is player " + str(player_num) + "'s name? ") if name.isalpha(): return name else: print("Please enter a valid name.") user_1 = get_player_name(1) user_2 = get_player_name(2) # Get number of rounds while True: try: rounds = int(input("How many rounds do you want to play? ")) if rounds > 0: # if round is not a number or is negative makes it sure you do it again break else: print("Please enter a positive number.") except ValueError: # if the value you put in was not a number and it break the code it check that and reset it print("Invalid input. Please enter a number.") # Game loop for round_num in range(1, rounds + 1): # Make it so it dispay the round number without displaying the amount you put for amount of round print("Round " + str(round_num) + " starts!") # prints the round number at every round chips_left = MAX_CHIPS # reset chips to 21 after every round while chips_left > 0: # round loop print("Chips left: " + str(chips_left)) # prints how many chips are left # Player 1's turn while True: try: chips_taken = int(input(user_1 + ", how many chips do you want to take (1-3)? ")) #input for many how chips you want if 1 <= chips_taken <= 3: # checks if it from 1 - 3 break else: print("You can only take 1, 2, or 3 chips.") except ValueError: # Check if a input is invalid like it not a number print("Invalid input. Please enter a number between 1 and 3.") chips_left -= chips_taken # minus chips taken from the amount of chips if chips_left <= 0: score_1 += 1 print(user_1 + " wins this round!") break print("Chips left: " + str(chips_left)) # prints how many chip are left after every turn # Player 2's turn while True: try: chips_taken = int(input(user_2 + ", how many chips do you want to take (1-3)? ")) if 1 <= chips_taken <= 3: break else: print("You can only take 1, 2, or 3 chips.") except ValueError: print("Invalid input. Please enter a number between 1 and 3.") chips_left -= chips_taken if chips_left <= 0: score_2 += 1 print(user_2 + " wins this round!") break # Check who wins print("Game over!") if score_1 > score_2: print(user_1 + " wins the game with " + str(score_1) + " points!") elif score_2 > score_1: print(user_2 + " wins the game with " + str(score_2) + " points!") else: print("It's a tie!")