Implement a function named get_player_selection. This function has parameters for the players number (which will be either 1 or 2), and the number of sticks remaining on the board. For this function you will need to do the following: Use the input function to get the playe
Implement a function named get_player_selection. This function has parameters for the players number (which will be either 1 or 2), and the number of sticks remaining on the board. For this function you will need to do the following: Use the input function to get the playe
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
- Implement a function named get_player_selection. This function has parameters for the players number (which will be either 1 or 2), and the number of sticks remaining on the board. For this function you will need to do the following:
- Use the input function to get the player to type in their selection.
- Validate the user’s input, printing out a message if they enter an invalid number and continually prompting them until they do enter a valid number. The user may enter any number between 1 and 3, unless there are fewer than 3 sticks remaining, in which case they can only enter between 1 and the number of sticks remaining. As in the example, the input prompt should list the valid range of numbers.
- Return the (validated) number as an integer (not a string).
- You should test that this function works by running it in the REPL. Make sure you try different scenarios, like the user entering an invalid number multiple times in a row. After you are done testing and fixing any errors you find, you should stage, commit, and sync your changes to avoid accidentally losing them.
- The test cases that you write for this function can be submitted for extra credit. Include them in a text document named tests.txt. For each test case, provide it with a header indicating what function you are testing and a unique test number. Then provide the code one must run in the REPL to run the test.
![```python
import random
def get_player_selection(player_number, sticks_left):
"""
parameters:
players number (either 1 or 2)
number of sticks remaining on the board
"""
input("Please type in your selection: ")
pass # remove this line when you start implementing your function
```
### Explanation
#### Lines 1-2
- **import random**: This line imports the `random` module, which provides functions for generating random numbers. This might be used later in the program for functionality that requires randomness.
#### Lines 4-23
- **def get_player_selection(player_number, sticks_left):**: This line defines a function named `get_player_selection` that takes two parameters: `player_number` and `sticks_left`.
#### Docstring (Lines 6-9)
- The docstring provides information about the parameters:
- **player_number**: Indicates the player making a selection, either player 1 or 2.
- **sticks_left**: Represents the number of sticks remaining on the board.
#### Line 11
- **input("Please type in your selection: ")**: Prompts the user to type in their selection. The input from the user is not stored or processed in the current implementation.
#### Line 13
- **pass**: A placeholder indicating that the function currently does nothing. It suggests removing this line when you start implementing the actual logic of the function.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff7722005-635d-4232-9de7-b0c3c13aa61f%2Ffb213023-8bc1-41f0-a1dc-3021e6f10009%2Fja2o4lx_processed.png&w=3840&q=75)
Transcribed Image Text:```python
import random
def get_player_selection(player_number, sticks_left):
"""
parameters:
players number (either 1 or 2)
number of sticks remaining on the board
"""
input("Please type in your selection: ")
pass # remove this line when you start implementing your function
```
### Explanation
#### Lines 1-2
- **import random**: This line imports the `random` module, which provides functions for generating random numbers. This might be used later in the program for functionality that requires randomness.
#### Lines 4-23
- **def get_player_selection(player_number, sticks_left):**: This line defines a function named `get_player_selection` that takes two parameters: `player_number` and `sticks_left`.
#### Docstring (Lines 6-9)
- The docstring provides information about the parameters:
- **player_number**: Indicates the player making a selection, either player 1 or 2.
- **sticks_left**: Represents the number of sticks remaining on the board.
#### Line 11
- **input("Please type in your selection: ")**: Prompts the user to type in their selection. The input from the user is not stored or processed in the current implementation.
#### Line 13
- **pass**: A placeholder indicating that the function currently does nothing. It suggests removing this line when you start implementing the actual logic of the function.
![**Example 1:**
Welcome to the game of sticks!
How many sticks are there on the table initially (10-100)? 10
There are 10 sticks on the board.
Player 1: How many sticks do you take (1-3)? 3
There are 7 sticks on the board.
Player 2: How many sticks do you take (1-3)? 3
There are 4 sticks on the board.
Player 1: How many sticks do you take (1-3)? 3
There is 1 stick on the board.
Player 2: How many sticks do you take (1-1)? 1
Player 2, you lose.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Ff7722005-635d-4232-9de7-b0c3c13aa61f%2Ffb213023-8bc1-41f0-a1dc-3021e6f10009%2Fwnfhyej_processed.png&w=3840&q=75)
Transcribed Image Text:**Example 1:**
Welcome to the game of sticks!
How many sticks are there on the table initially (10-100)? 10
There are 10 sticks on the board.
Player 1: How many sticks do you take (1-3)? 3
There are 7 sticks on the board.
Player 2: How many sticks do you take (1-3)? 3
There are 4 sticks on the board.
Player 1: How many sticks do you take (1-3)? 3
There is 1 stick on the board.
Player 2: How many sticks do you take (1-1)? 1
Player 2, you lose.
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY