# Player names input
player1 = str(input("Player 1. Please enter your name: "))
print(" ")
print("Hello", player1)
print("You are player 1.")
print(" ")
player2 = str(input("Player 2. Please enter your name: "))
print(" ")
print("Hello", player2)
print("You are player 2.")
print(" ")
# Initial pile states
pile_a = "*" * 10
pile_a_count = 10
pile_b = "*" * 12
pile_b_count = 12
pile_c = "*" * 8
pile_c_count = 8
# Welcome and rules prompt
print("Welcome", player1, "and", player2)
print("Do you wish to see the instructions before starting")
rules = input("Please enter 'True' or 'False' : ")
print(" ")
while rules == "True" or rules == "true" or rules == "yes" or rules == "Yes":
print(" ")
print("You will take turns to choose any pile A, B, or C")
print("You may remove 1, 2, or 3 stars from any pile")
print(" ")
print("The person to pick the last remaining star loses")
print(" ")
# Ask if they want to see the rules again
rules = input("Do you wish to see the rules again? Please enter 'True' or 'False': ")
print(" ")
#start the game
ready = input("Are you Ready? 'Yes' or 'No': ")
if ready == "Yes" or ready == "yes" or ready == "true" or ready == "True":
print("Great, let's begin")
else:
print("That's too bad, let's begin anyway!")
# ask who would like to make the first move
print(" ")
current_player = str(input("Who would like to go first? Player 1 or Player 2: "))
print(" ")
if current_player == "1" or current_player == "Player 1" or current_player == "Player1" or current_player
== "player 1" or current_player == "player1" or current_player == player1:
current_player = player1
print("Your turn,", player1)
print(" ")
if current_player == "2" or current_player == "Player 2" or current_player == "Player2" or current_player
== "player 2" or current_player == "Player2"or current_player == player2:
current_player = player2
print("Your turn,", player2)
print(" ")
print(" ")
print("Here are the current piles")
print("Pile A =", pile_a)
print("Pile B =", pile_b)
print("Pile C =", pile_c)
print(" ")
valid_pile = False
while not valid_pile:
pile_picked = str(input(f"{current_player}, Please pick a pile: "))
if (pile_picked == "A" or pile_picked == "a" or pile_picked == "B" or pile_picked == "b" or pile_picked
== "C" or pile_picked == "c"):
valid_pile = True # To exit the loop
else:
print("Invalid choice. Please pick a valid pile A, B, or C") # To keep re-entering if invalid pile picked
valid_number = False
while not valid_number:
number_picked = int(input("How many stars would you like to remove? 1, 2 or 3: "))
if number_picked == 1 or number_picked == 2 or number_picked == 3:
valid_number = True # To exit loop
else:
print("Invalid number. Please pick a valid number 1, 2, or 3") # To keep re-entering if invalid number
picked
if pile_picked == "A" or pile_picked == "a":
while number_picked > pile_a_count:
print("The number you have selected is more than the number of stars in the pile")
number_picked = int(input("Please re-enter your number: "))
pile_a_count = pile_a_count - number_picked
pile_a = "*" * pile_a_count
if pile_picked == "B" or pile_picked == "b":
while number_picked > pile_b_count:
print("The number you have selected is more than the number of stars in the pile")
number_picked = int(input("Please re-enter your number: "))
pile_b_count = pile_b_count - number_picked
pile_b = "*" * pile_b_count
if pile_picked == "C" or pile_picked == "c":
while number_picked > pile_c_count:
print("The number you have selected is more than the number of stars in the pile")
number_picked = int(input("Please re-enter your number: "))
pile_c_count = pile_c_count - number_picked
pile_c = "*" * pile_c_count
print(" ")
print("The new piles are as follows:")
print("Pile A =", pile_a)
print("Pile B =", pile_b)
print("Pile C =", pile_c)
if current_player == player1:
current_player = player2
else:
current_player = player1
# Repeating the process
while pile_a_count > 0 or pile_b_count > 0 or pile_c_count > 0:
print(" ")
print(f"{current_player}, it is your turn")
valid_pile = False
while not valid_pile:
pile_picked = str(input(f"{current_player}, Please pick a pile: "))
if pile_picked == "A" or pile_picked == "a" or pile_picked == "B" or pile_picked == "b" or pile_picked
== "C" or pile_picked == "c":
valid_pile = True # To exit the loop
else:
print("Invalid choice. Please pick a valid pile A, B, or C") # To keep re-entering if invalid pile picked
if (pile_picked == "A" or pile_picked == "a") and pile_a_count == 0:
print(" ")
print("Pile A is empty, Pick another pile")
valid_pile = False
if (pile_picked == "B" or pile_picked == "b") and pile_b_count == 0:
print(" ")
print("Pile B is empty, Pick another pile")
valid_pile = False
if (pile_picked == "C" or pile_picked == "c") and pile_c_count == 0:
print(" ")
print("Pile C is empty, Pick another pile")
valid_pile= False
valid_number = False
while not valid_number:
number_picked = int(input("How many stars would you like to remove? 1, 2 or 3: "))
if number_picked == 1 or number_picked == 2 or number_picked == 3:
valid_number = True # To exit loop
else:
print("Invalid number. Please pick a valid number 1, 2, or 3") # To keep re-entering if invalid
number picked
if pile_picked == "A" or pile_picked == "a":
while number_picked > pile_a_count:
print("The number you have selected is more than the number of stars in the pile")
number_picked = int(input("Please re-enter your number: "))
pile_a_count = pile_a_count - number_picked
pile_a = "*" * pile_a_count
if pile_picked == "B" or pile_picked == "b":
while number_picked > pile_b_count:
print("The number you have selected is more than the number of stars in the pile")
number_picked = int(input("Please re-enter your number: "))
pile_b_count = pile_b_count - number_picked
pile_b = "*" * pile_b_count
if pile_picked == "C" or pile_picked == "c":
while number_picked > pile_c_count:
print("The number you have selected is more than the number of stars in the pile")
number_picked = int(input("Please re-enter your number: "))
pile_c_count = pile_c_count - number_picked
pile_c = "*" * pile_c_count
if pile_a_count == 0 and pile_b_count == 0 and pile_c_count == 0:
print(" ")
print(f"{current_player}, loses! All piles are now empty.")
print(f"Better luck next time {current_player}")
print(" ")
if current_player == player1:
current_player = player2
else:
current_player = player1
print(f"The winner is {current_player}! Well done!")
print(" ")
print("Thank you for playing!")
break
print(" ")
print("The new piles are as follows:")
print("Pile A =", pile_a)
print("Pile B =", pile_b)
print("Pile C =", pile_c)
if current_player == player1:
current_player = player2
else:
current_player = player1