Skip to content

Commit ed47f3b

Browse files
committed
Add new file
1 parent 97c4e0d commit ed47f3b

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

rps.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""Rock
2+
Paper
3+
Scissors"""
4+
5+
from random import randint
6+
7+
8+
options = ["ROCK", "PAPER", "SCISSORS"]
9+
10+
message = {"tie":"Yawn it's a tie!",
11+
"won":"Yay you won!",
12+
"lost":"Aww you lost!"}
13+
14+
def decide_winner(user_choice, computer_choice):
15+
print user_choice
16+
print computer_choice
17+
18+
if user_choice == computer_choice:
19+
print message["tie"]
20+
21+
elif user_choice == options[0] and computer_choice == options[2]:
22+
print message["won"]
23+
24+
elif user_choice == options[1] and computer_choice == options[0]:
25+
print message["won"]
26+
27+
elif user_choice == options[2] and computer_choice == options[1]:
28+
print message["won"]
29+
30+
else:
31+
print message["lost"]
32+
33+
def play_rps():
34+
print "Rock, Paper or Scissors?"
35+
user_choice = raw_input("Enter your choice: ")
36+
user_choice = user_choice.upper()
37+
computer_choice = options[randint(0, 2)]
38+
return decide_winner(user_choice, computer_choice)
39+
40+
play_rps()

0 commit comments

Comments
 (0)