Question: Rock, paper, scissors code with input below.. import sys # Get User input and convert to lower case player1 = input('Enter Value for Player 1:
Rock, paper, scissors code with input below.. 

![1: ').lower() if player1 not in ['rock', 'paper', 'scissors']: print('Player 1 input](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f323dda4449_46166f323dd42d4e.jpg)
import sys
# Get User input and convert to lower case
player1 = input('Enter Value for Player 1: ').lower()
if player1 not in ['rock', 'paper', 'scissors']:
print('Player 1 input incorrect')
# loop to give three chances to get it right
for i in range(2):
player1 = input('Enter Value for Player 1: ').lower()
if player1 in ['rock', 'paper', 'scissors']:
break
else:
sys.exit('Exceeded maximum number of tries. Input Error')
player2 = input('Enter Value for Player 2: ').lower()
if player2 not in ['rock', 'paper', 'scissors']:
print('Player 2 input incorrect')
# loop to give three chances to get it right
for i in range(2):
player2 = input('Enter Value for Player 2: ').lower()
if player2 in ['rock', 'paper', 'scissors']:
break
else:
sys.exit('Exceeded maximum number of tries. Input Error')
# Game logic.
# Note that the backslash is a line continuation for long expressions
if player1 == player2:
print ('Players Tie')
elif (player1 == 'rock' and player2 == 'scissors') \
or (player1 == 'paper' and player2 == 'rock') \
or (player1 == 'scissors' and player2 == 'paper'):
print('Player 1 Wins')
else:
print('Player 2 Wins')
Assignment 4 - Functions 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. 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: Return 0 if it is a tie Return 1 if the winner is player 1 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
Get step-by-step solutions from verified subject matter experts
