# Libraries import random import time # Greetings/Names/Rounds print("Greetings, what are your names?") # Input for Player 1's name while True: player1 = input("\nPlayer 1: ") if player1.isalpha(): break else: print("\nPlease input a name, so I know you can input a number.") # Input for Player 2's name while True: player2 = input("\nPlayer 2: ") if player2.isalpha(): break else: print("\nPlease input a name, so I know you can input a number.") # Input for the number of rounds while True: try: rounds = input("\nHow many rounds? (1-5) ") if rounds.isdigit() and 1 <= int(rounds) <= 5: rounds = int(rounds) + 1 # Decrementing rounds to start from 0 print("Ok, let's begin!") rounds = int(rounds) break else: print("\nChoose a number between 1 and 5") except ValueError: print("Please input a valid number") # CONSTANTS MAXCHIPS = 21 # Variables score1 = 0 score2 = 0 # Game Start for _ in range(1, rounds): # Start from 1 to include the first round chips = MAXCHIPS while chips > 0: # Player 1's turn p1chips = 0 while p1chips == 0: try: p1chips = int(input("\n" + player1 + "'s turn. How many chips would you like to take? ")) if p1chips < 1 or p1chips > min(3, chips): print("\nChoose a number between 1 and", min(3, chips)) else: chips -= p1chips print("Chips remaining:", chips) if chips <= 0: score1 += 1 print("Player one wins!") print("\nPlayer 1 score:", score1) print("\nPlayer 2 score:", score2) break except ValueError: print("\nPlease input a number") if chips <= 0: break # Player 2's turn p2chips = 0 while p2chips == 0: try: p2chips = int(input("\n" + player2 + "'s turn. How many chips would you like to take? ")) if p2chips < 1 or p2chips > min(3, chips): print("\nChoose a number between 1 and", min(3, chips)) else: chips -= p2chips print("Chips remaining:", chips) if chips <= 0: score2 += 1 print("Player two wins!") print("\nPlayer 1 score:", score1) print("\nPlayer 2 score:", score2) break except ValueError: print("\nPlease input a number") # Print final scores print("Final scores:") print("Player 1 scored:", score1) print("Player 2 scored:", score2)