-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrps.py
92 lines (82 loc) · 2.71 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import random, sys
# Ascii art variables: Rock, Paper, Scissor
rock = '''
_______
---' ____)
(_____)
(_____)
(____)
---.__(___)
'''
paper = '''
_______
---' ____)____
______)
_______)
_______)
---.__________)
'''
scissors = '''
_______
---' ____)____
______)
__________)
(____)
---.__(___)
'''
# Variables
# List with Options for Computer to choose from.
choiceList = ['R','P','S']
# Stores User's Score.
userScore = 0
# Stores Computer's Score.
computerScore = 0
# Prompts the User with Instruction and Stores the Given Input for Game.
userInput = input("\n\nType 'Exit' to quit the program or 'Play' to play the game.")
# Main Game Loop
while True:
computerChoice = random.choice(choiceList)
if userScore == 5 or computerScore == 5:
break
elif userInput.lower() == 'exit':
sys.exit()
else:
userInput = input("\nPress (R) for Rock, (P) for Paper and (S) for Scissor: ").upper()
# The following bkock of code shows what you are choosing.
if userInput.upper() == 'R':
print(f"\nYou Choose: Rock\n{rock}")
elif userInput.upper() == 'P':
print(f"\nYou Choose: Paper\n{paper}")
elif userInput.upper() == 'S':
print(f"\nYou Choose: Scissors\n{scissors}")
# The following Block of code shows what the computer is choosing.
if userInput.upper() != 'R' and userInput.upper() != 'P' and userInput.upper() != 'S':
print("Wrong input! You can only choose from (R) Rock, (P) Paper or (S) Scissors.")
userScore += 0
computerScore += 0
continue
else:
if computerChoice == 'R':
print(f"Computer Choose: Rock\n{rock}")
elif computerChoice == 'P':
print(f"Computer Input: Paper\n{paper}")
else:
print(f"Computer Input: Scissors\n{scissors}")
# Score Adding Logic
if userInput == computerChoice.upper():
print(f"No Score! Opponent too choose {userInput}!")
elif userInput == 'R' and computerChoice == 'S':
userScore += 1
elif userInput == 'P' and computerChoice == 'R':
userScore += 1
elif userInput == 'S' and computerChoice == 'P':
userScore += 1
else:
computerScore += 1
print("\n\nSCORE BOARD:")
if userScore == computerScore:
print(f"\n\nDraw match!\nUser Score: {userScore}\nComputer Score: {computerScore}")
elif userScore > computerScore:
print(f"You Won!\Your Score: {userScore}\nComputer Score: {computerScore}")
else:
print(f"You Lose!\Your Score: {userScore}\nComputer Score: {computerScore}")