Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 10 Weeks Ago, 5 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
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.
-----------