Question
def winner_RPS(p1, p2): if p1 == p2: return None if (p1 == paper and p2 == rock) or (p1 == scissors and p2 ==
def winner_RPS(p1, p2): if p1 == p2: return None if (p1 == "paper" and p2 == "rock") or \ (p1 == "scissors" and p2 == "paper") or \ (p1 == "rock" and p2 == "scissors"): return p1 return p2
For this question, we are going to tidy up this solution by enforcing the following best practices:
-
Create the constants ROCK, PAPER, SCISSORS and update the code accordingly (i.e. there should only be one 'rock' in your code)
-
Have only a single exit point in the function. That is there should only be one return statement
-
Properly name the variable that you return (the one that holds the winner of RPS.
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