-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathrock_paper_scissor.py
More file actions
41 lines (31 loc) · 915 Bytes
/
Copy pathrock_paper_scissor.py
File metadata and controls
41 lines (31 loc) · 915 Bytes
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
import random
choices = ['rock', 'paper', 'scissor']
# What beats what
win_map = {
'rock': 'scissor',
'paper': 'rock',
'scissor': 'paper'
}
def get_computer_move():
return random.choice(choices)
def find_winner(user, comp):
if user == comp:
return "Tie"
elif win_map[user] == comp:
return "User Won"
else:
return "Computer Won"
print("===== Rock Paper Scissor =====")
while True:
if input("Play? (y/n): ").lower() != 'y':
print("Bye")
break
move = input("r/p/s: ").lower()
if move not in ['r', 'p', 's']:
print("Invalid input\n")
continue
user_move = {'r': 'rock', 'p': 'paper', 's': 'scissor'}[move]
computer_move = get_computer_move()
print("User:", user_move)
print("Computer:", computer_move)
print(find_winner(user_move, computer_move), "\n")