-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy path(8 kyu) Rock Paper Scissors.py
More file actions
33 lines (31 loc) · 1.06 KB
/
(8 kyu) Rock Paper Scissors.py
File metadata and controls
33 lines (31 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 1 Plain solution
def rps(p1, p2):
if p1 == "scissors" and p2 == "paper":
return "Player 1 won!"
elif p1 == "scissors" and p2 == "rock":
return "Player 2 won!"
elif p1 == "rock" and p2 == "paper":
return "Player 2 won!"
elif p1 == "rock" and p2 == "scissors":
return "Player 1 won!"
elif p1 == "paper" and p2 == "rock":
return "Player 1 won!"
elif p1 == "paper" and p2 == "scissors":
return "Player 2 won!"
else:
return "Draw!"
# 2 Optimized solution
def rps(p1, p2):
if p1 == p2: return "Draw!"
if p1 == "rock": return "Player 1 won!" if p2 == "scissors" else "Player 2 won!"
if p1 == "paper": return "Player 1 won!" if p2 == "rock" else "Player 2 won!"
if p1 == "scissors": return "Player 1 won!" if p2 == "paper" else "Player 2 won!"
# 3 Clever solution
def rps(p1, p2):
if p1 == p2: return "Draw!"
outcomes = {
"rock": "scissors",
"paper": "rock",
"scissors": "paper"
}
return "Player 1 won!" if outcomes[p1] == p2 else "Player 2 won!"