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...
icon
Related questions
Question
  1. 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.
12
import random
13
14
15
def get_player_selection(player_number, sticks_left):
16
17
parameters:
players number (either 1 or 2)
number of sticks remaining on the board
18
19
20
21
input("Please type in your selection: ")
22
23
pass # remove this line when you start implementing your function
24
Transcribed Image Text:12 import random 13 14 15 def get_player_selection(player_number, sticks_left): 16 17 parameters: players number (either 1 or 2) number of sticks remaining on the board 18 19 20 21 input("Please type in your selection: ") 22 23 pass # remove this line when you start implementing your function 24
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.
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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…
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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY