-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockPaperScissors.py
More file actions
92 lines (78 loc) · 2.64 KB
/
Copy pathRockPaperScissors.py
File metadata and controls
92 lines (78 loc) · 2.64 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
#Rock Paper Scissors
"""
Greet the user X
Ask the user to choose rock, paper, or scissors X
Do a little compute animation?
Show the results
Display win or lose
Ask the user if they'd like to play again
"""
import random
gameActive = True
playerName = 0
playerSelection = 0
cpuSelection = 0
roundActive = True
answer = 0
numberOfWins = 0
while gameActive:
while roundActive:
if playerName == 0:
playerName = input("Hello! Please enter your name: ")
print("Hello", playerName + "!") #the + eliminates the blank space between the variable value and the !
if playerSelection == 0:
playerSelection = input("Please choose rock, paper, or scissors: ")
print(playerName, "chose", playerSelection + ".")
#do some kind of animation or stall here
# if cpuSelection == 0:
cpuSelection = random.randint(1,4)
if cpuSelection == 1:
print("CPU chose rock.")
elif cpuSelection == 2:
print("CPU chose paper.")
elif cpuSelection == 3:
print("CPU chose scissors.")
if playerSelection == "rock":
if cpuSelection == 1:
print("Draw!")
roundActive = False
elif cpuSelection == 2:
print("You lost!")
roundActive = False
elif cpuSelection == 3:
print("You won!")
numberOfWins = numberOfWins + 1
roundActive = False
elif playerSelection == "paper":
if cpuSelection == 1:
print("You won!")
numberOfWins = numberOfWins + 1
roundActive = False
elif cpuSelection == 2:
print("Draw!")
roundActive = False
elif cpuSelection == 3:
print("You lost!")
roundActive = False
elif playerSelection == "scissors":
if cpuSelection == 1:
print("You lost!")
roundActive = False
elif cpuSelection == 2:
print("You won!")
numberOfWins = numberOfWins + 1
roundActive = False
elif cpuSelection == 3:
print("Draw!")
roundActive = False
if numberOfWins == 1:
print("You have won 1 time!")
elif numberOfWins >> 1:
print("You have won", numberOfWins, "times!")
answer = input("Do you want to play again? (y/n): ")
if answer == "y":
playerSelection = 0
cpuSelection = 0
roundActive = True
elif answer == "n":
gameActive = False