-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRock Paper Scissors.py
69 lines (58 loc) · 2.36 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import random
#function for continuing game loop if player wants to
def restart():
again = input("Play Again? y for YES, n for NO - ").lower()
#calling the game loop if player wants to
if again == "y":
game_loop()
#quiting the game if player wants to
elif again == "n":
print("Game Quit.")
else:
print("Quitting.")
#function containing the main game logic
def game_loop():
cpu_choices = ["Rock", "Paper", "Scissors"]
player_choices = ["Rock", "Paper", "Scissors"]
choice = random.randrange(0, 3) #creating random numbers for CPU to choose its move
cpu_choice = cpu_choices[choice] #picking CPU move
player_choice = input("Enter r for rock, p for papers or s for scissors: ").lower()
#conditions for when player chooses Rock
if player_choice == 'r':
player_choice = player_choices[0]
print("You: {}".format(player_choice)) #displaying player move
print("CPU: {}".format(cpu_choice)) #displaying CPU move
if player_choice == cpu_choice:
print("Draw.")
if player_choice == "Rock" and cpu_choice == "Paper":
print("CPU wins.")
if player_choice == "Rock" and cpu_choice == "Scissors":
print("You win.")
#conditions for when player chooses Paper
elif player_choice == 'p':
player_choice = player_choices[1]
print("You: {}".format(player_choice))
print("CPU: {}".format(cpu_choice))
if player_choice == cpu_choice:
print("Draw.")
if player_choice == "Paper" and cpu_choice == "Rock":
print("You win.")
if player_choice == "Paper" and cpu_choice == "Scissors":
print("CPU wins.")
#conditions for when player chooses Scissors
elif player_choice == 's':
player_choice = player_choices[2]
print("You: {}".format(player_choice))
print("CPU: {}".format(cpu_choice))
if player_choice == cpu_choice:
print("Draw.")
if player_choice == "Scissors" and cpu_choice == "Paper":
print("You win.")
if player_choice == "Scissors" and cpu_choice == "Rock":
print("CPU wins.")
#condition for when player chooses incorrect move
else:
print('Invalid move.')
restart()
#starting the game loop
game_loop()