-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrps_app.py
More file actions
58 lines (53 loc) · 1.44 KB
/
rps_app.py
File metadata and controls
58 lines (53 loc) · 1.44 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import random
def generate_quote(symbol):
'''
return the winning quote for symbols:
r -- rock,
p -- paper,
s -- scissors
'''
QUOTES = {
'r' : 'Rock smashes scissors!!!',
'p' : 'Paper covers rock!!',
's' : 'Scissors cuts paper'
}
if str(symbol) == '0':
pass
else:
return QUOTES[symbol.lower()[0]]
def get_rps_choice():
choices = ['rock','paper','scissors']
return random.choice(choices)
def get_rps_winner(a,b,quote=False):
'return winner of rock paper scissors 1 = a, 2 = b, 0 = tie'
rtn = 0
winner = 0
if a == b: # tie
pass
elif a.lower()[0] == 'r': # rock
if b.lower()[0] == 's': # beats scissors
rtn = 1
winner = 'r'
else:
rtn = 2 # loses to paper
winner = 'p'
elif a.lower()[0] == 'p': # paper
if b.lower()[0] == 'r': # beats rock
rtn = 1
winner = 'p'
else:
rtn = 2 # loses to scissors
winner = 's'
elif a.lower()[0] == 's': # scissors
if b.lower()[0] == 'p': # beats paper
rtn = 1
winner = 's'
else:
rtn = 2 # loses to rock
winner = 'r'
else:
raise IOError
if not quote:
return rtn
else:
return (rtn, generate_quote(winner))