forked from sanketpatil02/Code-Overflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRockPaperScissors.py
42 lines (37 loc) · 1.28 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
import random
import os
import re
# A program to play Rock, Paper, Scissors.
# Clear the console
os.system('cls' if os.name == 'nt' else 'clear')
i = 1
while i <= 5:
print("\n")
print("Rock, Paper, Scissors - Shoot!")
# The users' input
userChoice = input("Choose your weapon: Rock, Paper, or Scissors: ")
# Helps to look for a similar pattern and returns the first occurrence
if not re.match("[SsRrPp]", userChoice):
print("Please choose a letter: ")
print("Rock, Paper, Scissors - Shoot!")
continue
print(f"You chose: {userChoice}")
choices = ['R', 'P', 'S']
# The programs' random input
opponentChoice = random.choice(choices)
print(f"I chose: {opponentChoice}")
# Conditions to winning or losing
if opponentChoice == str.upper(userChoice):
print("Tie!!!")
elif opponentChoice == 'R' and userChoice.upper() == 'S':
print("Scissors beats rock, I win!")
continue
elif opponentChoice == 'S' and userChoice.upper() == 'P':
print("Scissors beats paper! I win!")
continue
elif opponentChoice == 'P' and userChoice.upper() == 'R':
print("Paper beat rock, I win!")
continue
else:
print("You win!")
i += 1