-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrock_paper_scissors.py
45 lines (35 loc) · 1.19 KB
/
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
36
37
38
39
40
41
42
43
44
45
import os
import re
import random
os.system('cls' if os.name == 'nt' else 'clear')
while True:
print("\n")
user_choice = input("Choose [R]ock, [P]aper or [S]cissors : ")
if not re.match("[RrPpSs]", user_choice):
print("Please choose a valid letter : [R]ock, [P]aper or [S]cissors")
continue
user_choice = str.upper(user_choice)
print("You chose:", user_choice)
choices = ['R', 'P', 'S']
opponent_choice = random.choice(choices)
print("I chose:", opponent_choice)
if opponent_choice == user_choice:
print("It's a Tie!")
elif user_choice == 'R':
if opponent_choice == 'S':
print("Rock crushes Scissors, You win!")
else:
print("Paper covers Rock, I win!")
elif user_choice == 'P':
if opponent_choice == 'R':
print("Paper covers Rock, You win!")
else:
print("Scissors cuts Paper, I win!")
elif user_choice == 'S':
if opponent_choice == 'P':
print("Scissors cuts Paper, You win!")
else:
print("Rock crushes Scissors, I win!")
play_again = input("Play again? (y/n): ")
if play_again.lower() != "y":
break