Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use python for coding! I need help with all parts. Your program must meet the following specifications. Note that control gets complex to play

Please use python for coding!

I need help with all parts.

image text in transcribed

Your program must meet the following specifications. Note that control gets complex to play this game: (one instructor used 4 while loops and 7 if statements) The program begins by offering a welcome message and display the rules of the game. Then, asking the player if he wants to play the game. That control is provided in the starting code provided. 1. 2. Initialize both piles to have 5 stones each. You will need a while loop to play the game (this will be in addition to the while loop in the provided code that is used to ask whether the human player wants to play another game.) What Boolean expression should control this loop? Hint: think about the size of piles. Play alternates between the human and computer. Use a Boolean variable to keep track of who is playing. The human player starts. 3. 4. Within this while loop a. When it is the human player's turn i. First prompt for the pile (1 or 2). Continue prompting until valid pile number is entered. A valid pile is non-empty and numbered 1 or 2. Next prompt for a number of stones to be removed from that pile. Continue prompting until a valid number of stones is entered. i. b. When it is the computer's turn i. Select the pile that the human player did NOT use on their turn. If the selected pile is empty, select the other pile, i.e. the one the human player used on their turn (note that if both piles are empty the game should have already ended) The number of stones to be removed by the computer is always 1 stone ii. Then, remove the stones from the pile. Display the number of stones in each pile after removal. Remember to switch players. c. 5. 6. The player who takes the last stone is the winner When the game has come to its conclusion, the program should output whether the human or the computer won. It then should display the cumulative record and ask the user whether to play again. (And if the user selects to play again, your program should.) If the user choose not to play the game again, the program should display a goodbye message Your program should verify that each of the user's moves is valid. (That is, the pile must be legal, the user must remove between 1 and 3 stones, and the user must not remove more stones than the pile holds.) If the user's move is illegal, your program should repeatedly print a sensible error message and get a new input, until the user selects a legal move 7. 8. Your program must meet the following specifications. Note that control gets complex to play this game: (one instructor used 4 while loops and 7 if statements) The program begins by offering a welcome message and display the rules of the game. Then, asking the player if he wants to play the game. That control is provided in the starting code provided. 1. 2. Initialize both piles to have 5 stones each. You will need a while loop to play the game (this will be in addition to the while loop in the provided code that is used to ask whether the human player wants to play another game.) What Boolean expression should control this loop? Hint: think about the size of piles. Play alternates between the human and computer. Use a Boolean variable to keep track of who is playing. The human player starts. 3. 4. Within this while loop a. When it is the human player's turn i. First prompt for the pile (1 or 2). Continue prompting until valid pile number is entered. A valid pile is non-empty and numbered 1 or 2. Next prompt for a number of stones to be removed from that pile. Continue prompting until a valid number of stones is entered. i. b. When it is the computer's turn i. Select the pile that the human player did NOT use on their turn. If the selected pile is empty, select the other pile, i.e. the one the human player used on their turn (note that if both piles are empty the game should have already ended) The number of stones to be removed by the computer is always 1 stone ii. Then, remove the stones from the pile. Display the number of stones in each pile after removal. Remember to switch players. c. 5. 6. The player who takes the last stone is the winner When the game has come to its conclusion, the program should output whether the human or the computer won. It then should display the cumulative record and ask the user whether to play again. (And if the user selects to play again, your program should.) If the user choose not to play the game again, the program should display a goodbye message Your program should verify that each of the user's moves is valid. (That is, the pile must be legal, the user must remove between 1 and 3 stones, and the user must not remove more stones than the pile holds.) If the user's move is illegal, your program should repeatedly print a sensible error message and get a new input, until the user selects a legal move 7. 8

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Handbook Of Database Security Applications And Trends

Authors: Michael Gertz, Sushil Jajodia

1st Edition

1441943056, 978-1441943057

More Books

Students also viewed these Databases questions