Rock Paper Scissors
Programming Basics · Python
TASK
Problem
Given two moves: `rock`, `paper`, or `scissors`. Print `FIRST`, `SECOND`, or `DRAW`.
EXAMPLE
Example
rock scissors
FIRST
LIMITS
Constraints
both moves are valid
LEARN
Theory for this problem
+
`input()` reads data entered by the user. The result of `input()` is initially a string. `split()` separates one input line into individual values using spaces. Comparison operators `==`, `!=`, `<`, `>`, `<=`, `>=` compare values and produce `True` or `False`. `and` requires all combined conditions to be true. `or` requires at least one condition to be true. `if` checks a condition and runs its block when the condition is true. `else` runs when the corresponding `if` condition is false. `print()` displays the program result. Print only what the problem statement requires.
**Connection to this task.** An `if` statement chooses a program branch from a Boolean condition. Comparisons produce `True` or `False`, and `elif` lets you test several mutually exclusive cases in order. The expression `'DRAW'` shows how this idea is applied to the task data.
NEED HELP?
Hints
+
['Equal moves mean draw; otherwise list the three winning pairs for player one.']
ANSWER
Solution
+
a, b = input().split()
if a == b:
print('DRAW')
elif a == 'rock' and b == 'scissors' or (a == 'scissors' and b == 'paper') or (a == 'paper' and b == 'rock'):
print('FIRST')
else:
print('SECOND')