-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_rock_paper.py
132 lines (104 loc) · 3.64 KB
/
game_rock_paper.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
"""
Name: Prachi Santosh Kolte
File Description: This file contains claasic game of 'Rock paper scissors spock lizard'. It accepts input from users
and simulates random option from computer which gives the effect of game whole.
"""
import random
game_choices = ['rock', 'paper', 'scissors', 'lizard', 'spock']
global player_score
global computer_score
def view_scores():
if (player_score > computer_score):
print("Player wins by {} numbers".format(player_score - computer_score))
elif (player_score < computer_score):
print("Computer wins by : {} numbers".format(computer_score - player_score))
else:
print("It's a tie!")
print("PLayer score is :{}".format(player_score))
print("Computer score is :{}".format(computer_score))
def main():
while (True):
print("Rock Paper Scissors Lizard Spock")
menu = """
---------------------------------
Main Menu:
---------------------------------
[1] Play
[2] Scores
[3] Exit
"""
print(menu)
option = (input("Select an option <3 to exit>:"))
if option == '1':
play_games()
elif option == '2':
view_scores()
elif option == '3':
print("Bye")
exit()
else:
print("wrong choice")
def play_games():
global player_score
global computer_score
player_score = 0
computer_score = 0
while (True):
options_display = """
Rock
Paper
Scissors
Lizard
Spock
"""
print(options_display)
your_choice = input("Enter Your choice <X to exit to the main menu>:")
computer_choice = (random.choice(game_choices))
print("Computer's choice:", computer_choice)
# print(computer_choice)
if your_choice.lower() in game_choices:
if your_choice == computer_choice:
print("Both are equal!")
player_score += 1
computer_score += 1
elif your_choice == 'spock':
if computer_choice == 'scissors' or computer_choice == 'rock':
print("You won !")
player_score += 2
else:
print("computer won!")
computer_score += 2
elif your_choice == 'lizard':
if computer_choice == 'spock' or computer_choice == 'paper':
print("You won !")
player_score += 2
else:
print("computer won!")
computer_score += 2
elif your_choice == 'scissors':
if computer_choice == 'lizard' or computer_choice == 'paper':
print("You won !")
player_score += 2
else:
print("computer won!")
computer_score += 2
elif your_choice == 'rock':
if computer_choice == 'scissors' or computer_choice == 'lizard':
print("You won !")
player_score += 2
else:
print("computer won!")
computer_score += 2
elif your_choice == 'paper':
if computer_choice == 'spock' or computer_choice == 'rock':
print("You won !")
player_score += 2
else:
print("computer won!")
computer_score += 2
elif your_choice == 'X':
return 0
else:
print("Invalid Choice!")
if __name__ == '__main__':
main()