forked from TigerhawkT3/small_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrock_paper_scissors.py
35 lines (31 loc) · 984 Bytes
/
rock_paper_scissors.py
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
import random
def rand(l=['rock', 'paper', 'scissors']):
return random.choice(l)
def win(player, difficulty):
c = choices.get(difficulty, {}).get(player, rand)()
result = player+c[0]
return 'Computer plays {}. {}'.format(c, results.get(result, 'Tie.'))
choices = {'e':{'r':lambda: 'scissors',
's':lambda: 'paper',
'p':lambda: 'rock'},
'h':{'r':lambda: 'paper',
's':lambda: 'rock',
'p':lambda: 'scissors'}
}
results = {'rp':'You lose!',
'rs':'You win!',
'pr':'You win!',
'ps':'You lose!',
'sr':'You lose!',
'sp':'You win!',
}
difficulty = 'e'
if __name__ == '__main__':
while 1:
i = input('Enter a difficulty, play, or quit: ').lower()[:1]
if i == 'q':
break
if i in set('emh'):
difficulty = i
elif i in set('rps'):
print(win(i, difficulty))