#-------------------------------------------------------------------------- # Name : Pick up game # Purpose : 11DGT # Author: Trey Simpson # Created : 10/03/2025 # Copyright : © Trey Simpson, 14.03.25 #-------------------------------------------------------------------------- # Import libraries import time import random # Presets max_chips = 21 PlayerOneScore = 0 PlayerTwoScore = 0 chipsleft = 0 chipstaken = 0 # Greeting message print("Welcome to the 21 take away game!") time.sleep(1) # Asking for valid name for Player 1 while True: Player1Name = input("What is the first player's name? ") if Player1Name.isalpha() == True: # Check if the input is a string (only letters) break # If valid, break out of the loop else: print("Retry and please enter a string input. ") time.sleep(0.5) # Asking for valid name for Player 2 while True: Player2Name = input("What is the second player's name? ") if Player2Name.isalpha() == True: # Check if the input is a string (only letters) break # If valid, break out of the loop else: print("Retry and please enter a string input. ") time.sleep(0.5) # Asking for a valid number input for how many rounds to play while True: try: rounds = int(input("How many rounds would you like to play? 1-5 ")) if rounds < 1 or rounds > 5: # Check if the number of rounds is between 1 and 5 print("Please choose a number between 1 and 5 ") else: break # Break out of the loop except: print("Please input a valid integer. ") # Retry if its not a number time.sleep(0.5) print("") # Rounds loop while rounds > 0: chipsleft = max_chips # Reset chips to the initial number at the start of each round while chipsleft > 0: # Continue until all chips are taken # Player 1's turn print("There are", chipsleft, "chips left") try: chipstaken = int(input("How many chips would you like to take " + Player1Name + "? (1-3) ")) if chipstaken < 1 or chipstaken > 3: # Check if the input is between 1 and 3 print("You can only take between 1 and 3 chips.") continue chipsleft -= chipstaken # Subtract the number of chips Player 1 took from the total except ValueError: print("Please enter a valid number.") continue if chipsleft <= 0: # Check if Player 1 has won the round PlayerOneScore += 1 print("Congrats", Player1Name, ", you win this round!") break # End the round time.sleep(0.5) # Player 2's turn print("There are", chipsleft, "chips left") # Show how many chips are left try: chipstaken = int(input("How many chips would you like to take " + Player2Name + "? (1-3) ")) if chipstaken < 1 or chipstaken > 3: # Check if the input is between 1 and 3 print("You can only take between 1 and 3 chips.") continue chipsleft -= chipstaken # Subtract the number of chips Player 2 took from the total except ValueError: print("Please enter a valid number.") continue time.sleep(0.5) if chipsleft <= 0: # Check if Player 2 has won the round PlayerTwoScore += 1 # Increase Player 2's score print("Congrats ", Player2Name, "you win this round!") break # End the round time.sleep(0.25) rounds -= 1 # Minus a round print(rounds, "rounds left") time.sleep(0.5) # After all rounds are done if PlayerOneScore > PlayerTwoScore: # Player 1 wins print("Congrats on the win", Player1Name, "! Final Score: ", PlayerOneScore) elif PlayerTwoScore > PlayerOneScore: # Player 2 wins print("Congrats on the win", Player2Name, "! Final Score: ", PlayerTwoScore) else: # Tie print("It's a tie!")