-
Notifications
You must be signed in to change notification settings - Fork 0
/
RPS.py
59 lines (49 loc) · 1.79 KB
/
RPS.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
51
52
53
54
55
56
57
58
59
import random
import os
import re
def checkStatus():
valid_responses = ['y', 'n']
while True:
try:
response = input('Do you wish to play again? (Yes (y) or No (n)): ')
if response.lower() not in valid_responses:
raise ValueError('Yes or No only')
if response.lower() == 'y':
return True
else:
os.system('cls' if os.name == 'nt' else 'clear')
print('Thanks for playing!')
exit()
except ValueError as err:
print(err)
def playRPS():
play = True
while play:
os.system('cls' if os.name == 'nt' else 'clear')
print('')
print('Rock, Paper, Scissors - Shoot!')
userChoice = input('Choose your weapon'
' Rock (R), Paper (P), or Scissors (S): ')
if not re.match("[SsRrPp]", userChoice):
print('Invalid input. Please choose a letter:')
print('Rock (R), Paper (P), or Scissors (S)')
continue
print(f'You chose: {userChoice}')
choices = ['R', 'P', 'S']
oppChoice = random.choice(choices)
print(f'I chose: {oppChoice}')
if oppChoice == userChoice.upper():
print('Tie!')
play = checkStatus()
elif oppChoice == 'R' and userChoice.upper() == 'S':
print('Rock beats scissors, I win!')
play = checkStatus()
elif oppChoice == 'S' and userChoice.upper() == 'P':
print('Scissors beats paper! I win!')
play = checkStatus()
elif oppChoice == 'P' and userChoice.upper() == 'R':
print('Paper beats rock, I win!')
play = checkStatus()
else:
print('You win!\n')
play = checkStatus()