-
Notifications
You must be signed in to change notification settings - Fork 2
/
RockPaperScissors.py
50 lines (45 loc) · 1.98 KB
/
RockPaperScissors.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# This program illustrates a game of Rock Paper Scissors.
# RULES:
# Rock beats scissors
# Scissors beats paper
# Paper beats rock
import random, time
def rockPaperScissors():
# R => Rock, P => Paper, S => Scissors
computerOptions = ['R', 'P', 'S']
computer = computerOptions[random.randint(0, 2)]
forOptions = {'R': 'Rock', 'P': 'Paper', 'S':'Scissors'}
try:
player = input('Enter your choice [R]ock [P]aper [S]cissors: ')
player = player.upper()
if player in computerOptions:
if player == computer:
print('Player:',forOptions.get(player),'Computer:',forOptions.get(computer))
print('You both tied!')
elif player == 'R':
if computer == 'P':
print('Player:',forOptions.get(player),'Computer:',forOptions.get(computer))
print('Sorry, you lose! Try again.')
else:
print('Player:',forOptions.get(player),'Computer:',forOptions.get(computer))
print('Congrats, you win!')
elif player == 'S':
if computer == 'R':
print('Player:',forOptions.get(player),'Computer:',forOptions.get(computer))
print('Sorry, you lose! Try again.')
else:
print('Player:',forOptions.get(player),'Computer:',forOptions.get(computer))
print('Congrats, you win!')
elif player == 'P':
if computer == 'S':
print('Player:',forOptions.get(player),'Computer:',forOptions.get(computer))
print('Sorry, you lose! Try again.')
else:
print('Player:',forOptions.get(player),'Computer:',forOptions.get(computer))
print('Congrats, you win!')
else:
print('Please enter only R, P or S as your choice')
except:
exit()
if __name__ == '__main__':
rockPaperScissors()