Question
This is all in PYTHON code. import sys # Get User input count = 0 player1 = while count count = 0 player2 =
This is all in PYTHON code.
import sys
# Get User input count = 0 player1 = "" while count
count = 0 player2 = "" while count In this assignment we are going to enhance the Rock Paper Scissors game so that the code that our code is reusable. We will do this through the use of functions. A function is a block of code that has the following attributes: Name: Every function has a name that you use to call the function Arguments: A function can have 0 or more arguments that represent values that you pass into the function. Arguments are usually used to impact the way that the function will process. Return: A function should have one or more return values. These are usually the results of the function process or sometimes an error code. Task 1: In our previous assignment we created code that checked the input of the data provided by the players. In this task we are going to create a function that will do the check. Here are the requirements for the function. The function name will be RPSValidate. The function will take one argument which is the input that you get from the user. In the function, check to see that the value of the argument is either rock, paper, or scissors. If the validation passes, return the input value converted to lower case. As an example, if the input value you pass as an argument is ROCK, this is valid but you would return the value rock as the return value of the function. If the validation does not pass, return the string 'input error' from the function. Task 2: The actual gameplay of the RPS game will be in another function. Here are the requirements for this second function. The function name will be RPSExecute. The function will take two arguments called player1 and player2. Since these arguments will be validated inputs, there are three possible return values: o Return 0 if it is a tie o Return 1 if the winner is player 1 O Return 2 if the winner is player 2 Task 3: Call the two functions by using the following logic: Use the Python Input function to get the value for player 1 and validate it using RPSValidate. Make sure that the user only gets three attempts to try the input. Exit the app if they fail. Do the same for player two. If you are at this stage, both player inputs should be valid, and they will have been converted to lower case. Call the RPSExecute function and pass the validated inputs for player 1 and player 2. Depending on the return value that you get from the RPSExecute function, output the result of the game to the notebook
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started