Question
import sys # Get User input count = 0 player1 = while count < 3: player1 = input('Enter Value for Player 1: ') player1
import sys
# Get User input count = 0 player1 = "" while count < 3: player1 = input('Enter Value for Player 1: ') player1 = player1.lower() if (player1 != 'rock' and player1 != 'paper' and player1 != 'scissors'): print('Player1 input incorrect') count = count + 1 else: break if count == 3: sys.exit("Input Error")
count = 0 player2 = "" while count < 3: player2 = input('Enter Value for Player 2: ') player2 = player2.lower() if (player2 != 'rock' and player2 != 'paper' and player2 != 'scissors'): print('Player2 input incorrect') count = count + 1 else: break if count == 3: sys.exit("Input Error") # Game logic. # Note that the backslash is a line continuation for long expressions if (player1 == 'rock' or player1 == 'paper' or player1 == 'scissors') \ and (player2 == 'rock' or player2 == 'paper' or player2 == 'scissors'): 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') else: print('Input Incorrect')
-
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.
-
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