-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPP_008.py
More file actions
93 lines (77 loc) · 2.51 KB
/
PP_008.py
File metadata and controls
93 lines (77 loc) · 2.51 KB
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
93
# PythonPractice_006: Rock Paper Scissors
# Remember the rules:
# - Rock beats scissors
# - Scissors beats paper
# - Paper beats rock
import random
def RockPaperScissor(usrSelection):
gameOptions = ['ROCK', 'PAPER', 'SCISSOR']
sysChoice = gameOptions[random.randint(0, 2)]
if usrSelection in ['ROCK', 'R']:
usrSelection = 'R'
elif usrSelection in ["PAPER", 'P']:
usrSelection = 'P'
elif usrSelection in ["SCISSOR", 'S']:
usrSelection = 'S'
if sysChoice in ['ROCK', 'R']:
sysChoice = 'R'
elif sysChoice in ["PAPER", 'P']:
sysChoice = 'P'
elif sysChoice in ["SCISSOR", 'S']:
sysChoice = 'S'
print('usrSelection: %s, sysChoice: %s' % (usrSelection, sysChoice))
if sysChoice == usrSelection:
print('Its a Tie')
elif sysChoice == 'R':
if usrSelection == 'S':
print("Sorry.. You Loose.")
elif usrSelection == 'P':
print("Hurray.. You Win.")
elif sysChoice == 'S':
if usrSelection == 'P':
print("Sorry.. You Loose.")
elif usrSelection == 'R':
print("Hurray.. You Win.")
elif sysChoice == 'P':
if usrSelection == 'R':
print("Sorry.. You Loose.")
elif usrSelection == 'S':
print("Hurray.. You Win.")
return
def menuFunction():
usrInput = False
trueChoice = ['YES', 'NO', 'Y', 'N']
while usrInput not in trueChoice:
usrInput = input("Do you want to play again? Yes(Y)/No(N): ")
usrInput = usrInput.upper()
if usrInput not in trueChoice:
print("Invalid Input.")
return usrInput
def UserInput():
gameOptions = ['ROCK', 'PAPER', 'SCISSOR', 'R', 'P', 'S']
while True:
usrCh = input("Please choose your turn: [ROCK (R), PAPER (P), SCISSOR (S)]\n ")
usrCh = usrCh.upper()
if usrCh in gameOptions:
break
else:
print("Invalid choice")
return usrCh
# ---------------------------------------
# Main Function/Method
# ---------------------------------------
print("Let's play ROCK, PAPER & SCISSOR Game:\n")
playOn = 'Y'
while playOn == 'Y':
usrChoice = UserInput()
print("usrChoice: %s" % usrChoice)
if playOn in ['YES', 'Y']:
print("playOn: %s" % playOn)
RockPaperScissor(usrChoice)
playOn = menuFunction()
if playOn in ['NO', 'N']:
print("\n--- Have a Nice Day ---")
break
else:
if playOn not in ['YES', 'Y']:
print("Invalid Input.\n")