Rock Paper Scissors Winner

Medium ⏱ 12 min 49% acceptance ★★★★★ 4.6
Write a function rps_winner(p1, p2) where p1 and p2 are each "rock", "paper", or "scissors". Return "Player 1" or "Player 2" for the winner, or "Draw" if they match. Standard rules: rock beats scissors, scissors beats paper, paper beats rock.

Examples

Example 1
Input
rps_winner("rock", "scissors")
Output
"Player 1"
Explanation

Rock beats scissors.

Example 2
Input
rps_winner("paper", "paper")
Output
"Draw"
Explanation

Identical moves draw.

Example 3
Input
rps_winner("scissors", "rock")
Output
"Player 2"
Explanation

Rock beats scissors, so player 2 wins.

Constraints

  • p1 and p2 are each one of "rock", "paper", "scissors".

Topics

Conditional Statementsnested conditionals

Companies

AtlassianServiceNow

Hints

Hint 1

Check the draw case first as a guard clause.

Hint 2

List the three winning combinations for Player 1 explicitly.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.