Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. Create the constants ROCK, PAPER, SCISSORS and update the code accordingly (i.e. there should only be one 'rock' in your code)

  2. Have only a single exit point in the function. That is there should only be one return statement

  3. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions