Python 3 Write a Python program to play a simplified version
Python 3
Write a Python program to play a simplified version of the Nim game. Generate a pile of between 15 and 21 inclusive matchsticks using the random number generator. Allow the human player to go first and remove from 1 to 3 sticks. Then allow the computer to generate a random number between 1 and 3 inclusive and remove that many matchsticks(exception example: if the number is 3 and there are only 2 matchsticks left, then only remove 1 matchstick). Playalternates until 1 matchstick is left and the losing player removes it. Declare the winner and ask if the user would like to play another game.
Validate the input and write the following functions:
-computer_play(pile) –figures out how many sticks the computer will remove and returns the number of sticks to remove
-player_play(pile) –solicits input from the user as to how many sticks to remove, validates the input, and returns the number of sticks the player wants to remove
-print_gameboard(pile) –prints a vertical bar for each matchstick on one line with one space between each matchstick.
-main () –main function which allows the user to play the game as many times as desired; validates all input
Please go to the web site, http://www.archimedes-lab.org/game_nim/play_nim_game.html, and play the game to learn it’s rules.
Solution
1) computer_play(pile)- in this function firstly we have to describe that player 1 is computer and display how many stocks it choose
remove1=intA(raw_input(\"Player 1 how many sticks do you want to remove? \"))
if remove>3 or remove <1:
print \"That is not a legal amount.\"
elif remove>sticks:
print \"You are trying to remove more sticks than there are left.\"
elif remove== sticks Similarly in user function every thing will be similar but the limit to select the matchstick will be lesser than user 1 suppose like out of 3 if one matchstick is removed by user 1 , user second can remove only one matchstick. 3)
main()
