Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Python 3 8. The Game of Nims (extra credit) In this game, two players sit in front of a pile of 100 stones. They

In Python 3image text in transcribedimage text in transcribed

8. The Game of Nims (extra credit) In this game, two players sit in front of a pile of 100 stones. They take turns, each removing between 1 and 5 stones (assuming there are at least 5 stones left in the pile). The person who removes the last stone(s) wins. In this problem, you'll write a function to play this game. It may seem tricky, so break it down into parts. Like many programs, we have to use nested loops (one loop inside another). In the outermost loop, we want to keep playing until we are out of stones. Inside that, we want to keep alternating players. You have the option of either writing two blocks of code, or keeping a variable that tracks the current player. We are going to use the input function to obtain the user's move. We might want to have an innermost loop that checks if the user's input is valid. Is it a number? Is it a valid number (e.g. between 1 and 5)? Are there enough stones in the pile to take off this many? If any of these answers are no, the user and re-ask them the question. we should tell If you choose to write two blocks of code, the basic outline of the program should be something like this: while pile is not empty]: while [player l's answer is not valid]: lask player 1] execute player 1's move same as above for player 2] Be careful with the validity checks. Specifically, we want to keep asking player 1 for their choice as long as their answer is not valid, BUT we want to make sure we ask them at least ONCE. So, for example, we will want to keep a variable that tracks whether their answer is valid, and set it to False initially. There is no need to limit yourself to only one function! Use as many functions as you want in order to make the code more readable and modular. When you're finished, test each other's programs by playing them

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago