Repository navigation
Expand file tree
/
Copy pathcommand-line-game
More file actions
182 lines (144 loc) · 6.71 KB
/
Copy pathcommand-line-game
File metadata and controls
182 lines (144 loc) · 6.71 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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#Stone Paper and Scissors game using PYTHON
#Command line version using Stone Paper and Scissors game using PYTHON
import random
#prints out the basic rules involved in the game for the user
#user manual
def rules():
print("******** "+"WELCOME TO THE COMMAND LINE VERSION OF ROCK,PAPER AND SCISSORS GAME USING PYTHON" + "\t" + "********")
print("\n")
print("Game can be won according to the following rule :")
print("\t" +"\t" + "Rock V/S Paper => PAPER WINS!")
print("\t" + "\t" +"Rock V/S Scissor => ROCK WINS!")
print("\t" + "\t" +"Paper V/S Scissor => SCISSOR WINS!")
print("\n")
#Asks the user to choose their move.
def user_moves():
user_choice = input("Choose ROCK or PAPER or SCISSORS :")
if user_choice in [ "ROCK" , "Rock" , "rock" , "R" , "r" ] :
user_choice = "r"
elif user_choice in ["PAPER" , "Paper" , "paper" , "P" , "p" ] :
user_choice = "p"
elif user_choice in ["SCISSORS" , "Scissors" , "SCISSOR" , "Scissor" , "scissor" , "scissors" , "S" , "s" ] :
user_choice = "s"
else:
print("Please use some valid answer!")
user_moves()
return user_choice
#Computer randomly selects between the three options provided i.e. Rock , Paper and Scissor.
def comp_moves():
list = ["r", "s", "p"]
comp_choice = random.choice(list)
return comp_choice
#Where all the statements are checked and the result is printed out.
def compare():
user_score = 0
computer_score = 0
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
while True:
print("\n")
user_option = user_moves()
comp_option = comp_moves()
print("\n")
#comparission line number 1
if user_option == "r":
if comp_option == "r":
print("You chose ROCK. The computer chose a ROCK.")
print("********"+"\t"+"ITS A TIE!" +"\t"+"********")
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
if comp_option == "p":
print("You chose ROCK. The computer chose a PAPER.")
print("********"+"\t"+"COMPUTER WINS THE GAME !"+"\t"+"********")
computer_score += 1
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
if comp_option == "s":
print("You chose ROCK. The computer chose a PAPER.")
print("********"+"\t"+"YOU WIN THE GAME !"+"\t"+"********"+"\t")
user_score += 1
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
#comparission line number 2
if user_option == "p":
if comp_option == "r":
print("You chose PAPER. The computer chose a ROCK.")
print("********"+"\t"+"YOU WIN THE GAME !"+"\t"+"********"+"\t")
user_score += 1
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
if comp_option == "p":
print("You chose PAPER. The computer chose a PAPER.")
print("********"+"\t"+"ITS A TIE!"+"\t"+"********"+"\t")
#printing the score here
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
if comp_option == "s":
print("You chose PAPER. The computer chose a SCISSOR.")
print("********"+"\t"+"COMPUTER WINS THE GAME !"+"\t"+"********"+"\t")
computer_score += 1
#printing the score here
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
#comparission line number 3
if user_option == "s":
if comp_option == "r":
print("You chose SCISSOR. The computer chose a ROCK.")
print("********"+"\t"+"COMPUTER WINS THE GAME !"+"\t"+"********")
computer_score += 1
#printing the score here
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
if comp_option == "p":
print("You chose SCISSOR. The computer chose a PAPER.")
print("********"+"\t"+"YOU WIN THE GAME !"+"\t"+"********"+"\t")
user_score += 1
#printing the score here
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
if comp_option == "s":
print("You chose SCISSOR. The computer chose a SCISSOR.")
print("********"+"\t"+"ITS A TIE!" +"\t"+ "********"+"\t")
#Printing the score here!
print("\n")
print("Scores :")
print("\n")
print("User points:" , user_score , "\t" + "\t" + "\t" + "Computer points:" , computer_score)
if computer_score == 5 or user_score == 5 :
if computer_score == 5 :
print("\n")
print("Computer got 5 points! Computer wins this set of game")
print("\n")
return 0
elif user_score == 5 :
print("\n")
print("User got 5 points! User wins this set of game")
print("\n")
return 0
print("\n")
move = input("Do you want to play again ? (Y/N)")
if move in ["Y" , "y" ,"Yes" , "yes"]:
pass
elif move in ["n" , "N" , "No" , "no"]:
break
#Calling all the functions
rules()
compare()