Hi, I'm a complete noob to Python so please be nice!
I am writing a game of nim program and I've come across an issue where I've managed to get the game to work against a computer. However I get the following errors:
If you empty pile 2, the game decides the player 2 as the winner without clearing pile 1 and vice versa if you clear pile 1.
I've entered the entirety of my code below, or if preferable, I've attached a zip file of my code.
GameOfNim Computer.zip (Size: 1.5 KB / Downloads: 66)
, it contains a 1 v computer game and a 2 human player game.
Appreciate the assistance on this!
Thanks
Daz
------------------------------------------------------------------

I am writing a game of nim program and I've come across an issue where I've managed to get the game to work against a computer. However I get the following errors:
If you empty pile 2, the game decides the player 2 as the winner without clearing pile 1 and vice versa if you clear pile 1.
I've entered the entirety of my code below, or if preferable, I've attached a zip file of my code.

Appreciate the assistance on this!
Thanks
Daz
------------------------------------------------------------------
#game of nim Part #set the initial state import random def main(): randPile = random.randint(2, 5) player = player1 print(randPile) #post: play again question def playAgain(): playAgainAnswer = input("Would you like to play again? type 'yes' to play again or anything else to quit: ") playAgainAnswer = playAgainAnswer.capitalize() if playAgainAnswer == "Yes": playGame() else: print("Thank you for playing, goodbye") #If playing against computer def playAgainstComputer(): print("-" * 25) print("PLAYER VS COMPUTER") print("-" * 25) player1 = input("Enter player 1 name: ") computer = "Computer" pile1 = random.randint(2, 10) pile2 = random.randint(2, 10) print("-" * 25) print(" Token pile 1:", pile1 * "O") print(" Token pile 2:", pile2 * "O") print("-" * 25) currentPlayer = player1 while pile1 > 0 and pile2 > 0: #Stating player turn and which pile to remove from print("-" * 25) print(currentPlayer.upper(), "TURN") print("-" * 25) if currentPlayer == computer: #Computers Turn computerChoosesPile = random.randint(1, 2) print("Computer chooses token pile:", computerChoosesPile) computerRemoveTokens = random.randint(1, 4) print("Computer removes", computerRemoveTokens * "O", "token(s)") if computerChoosesPile == 1: pile1 = pile1 - computerRemoveTokens print("Pile 1 now has ", pile1 * "O", " token(s) left") else: pile2 = pile2 - computerRemoveTokens print( "Pile 2 now has ", pile2 * "O", " token(s) left") else: while True: pileChoice = int(input(currentPlayer + " which pile do you want to take tokens from, pile 1 or pile 2? ")) #remove Tokens from pile choice from player 1 if pileChoice == 1: while True: removeTokens = int(input("How many tokens to remove? ")) if removeTokens <= 0 or removeTokens > pile1: print("That's an invalid number, try again") else: pile1 = pile1 - removeTokens print("Pile 1 now has ", pile1 * "O", " token(s) left") break #remove Tokens from pile choice from computer elif pileChoice == 2: while True: removeTokens = int(input("How many tokens to remove? ")) if removeTokens <= 0 or removeTokens > pile2: print("That's an invalid number, try again") else: pile2 = pile2 - removeTokens print("Pile 2 now has ", pile2 * "O", " token(s) left") break else: print("error, please choose only 1 or 2") if pileChoice == 1 or pileChoice == 2: break # Decide who's turn is next if currentPlayer == player1: currentPlayer = computer else: currentPlayer = player1 # Decide who's won print("DECIDING...") if pile1 and pile2 <= 0: winner = computer else: winner = player1 print("Winner...congratulations,", winner,"!") playAgain() #If playing against another player def playAgainstPlayer(): print("-" * 25) print("PLAYER VS PLAYER") print("-" * 25) player1 = input("Enter player 1 name: ") player2 = input("Enter player 2 name: ") pile1 = random.randint(2, 10) pile2 = random.randint(2, 10) print("Token pile 1:", pile1 * "O") print("Token pile 2:", pile2 * "O") currentPlayer = player1 while pile1 > 0 and pile2 > 0: #get valid move while True: print("-" * 25) print(currentPlayer.upper(), "TURN") print("-" * 25) pileChoice = int(input(currentPlayer + " which pile do you want to take tokens from, pile 1 or pile 2? ")) #remove Tokens from pile choice from pile 1 if pileChoice == 1: while True: removeTokens = int(input("How many tokens to remove? ")) if removeTokens <= 0 or removeTokens > pile1: print("That's an invalid number, try again") else: pile1 = pile1 - removeTokens print("Pile 1 now has ", pile1 * "O", " token(s) left") break #remove Tokens from pile choice from pile 2 elif pileChoice == 2: while True: removeTokens = int(input("How many tokens to remove? ")) if removeTokens <= 0 or removeTokens > pile2: print("That's an invalid number, try again") else: pile2 = pile2 - removeTokens print("pile 2 now has ", pile2 * "O", " token(s) left") break else: print("error, please choose only 1 or 2") if pileChoice == 1 or pileChoice == 2: break # Decide who's turn is next if currentPlayer == player1: currentPlayer = player2 else: currentPlayer = player1 # Decide who's won print("DECIDING...") if playerOnePile <= 0: winner = player2 else: winner = player1 print("Winner, congratulations!", winner) playAgain() def playGame(): gameType = input(str("Enter 1 for 1 v computer or 2 for 2 players? ")) if gameType == "1": playAgainstComputer() elif gameType == "2": playAgainstPlayer() else: print("Invalid choice, try again") return(gameType) playGame()