Skip to content

Commit 7c9acd8

Browse files
Merge pull request #3007 from rajanitnavapara/master
Create StonePaperScissorGame.py
2 parents c32d72b + 5d1dcaa commit 7c9acd8

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

StonePaperScissorGame.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
#Importing random
2+
import random
3+
4+
#creating a list of elements of game and define variable.
5+
elements = ["Stone","Scissor","Paper"]
6+
global human #global for using the variabe in function
7+
global com
8+
human = 0
9+
com = 0
10+
11+
#for displaying choices.
12+
def display_choices():
13+
print("Now you're going to play Stone Paper Scissor game.")
14+
print("You need 10 points to win the match.")
15+
print("Here are your Choices :- ")
16+
print("Stone : 1")
17+
print("Scissor : 2")
18+
print("Paper : 3")
19+
20+
#main gameplay.
21+
def play_game(human,com):
22+
23+
#humanc = int(input("Enter the choice here 1-3 : "))
24+
num = int(input("Enter the choice here 1-3 : "))
25+
humanc = validate(num)
26+
27+
comc = random.randint(1,3)
28+
display_result(humanc, comc)
29+
30+
winner(humanc, comc)
31+
32+
points()
33+
34+
#for decide who is winner.
35+
def winner(c1,c2):
36+
global com
37+
global human
38+
if c1 == c2:
39+
print("Draw")
40+
return None
41+
elif c1 < c2 :
42+
if c1 == 2 and c2==3:
43+
human += 1
44+
print("Congratulations!...You Win.")
45+
return None
46+
elif c2 != 3:
47+
human += 1
48+
print("Congratulations!...You Win.")
49+
#print(f"P1 : {human}")
50+
return None
51+
else:
52+
com+=1
53+
print("Oops!...Best of luck next time.")
54+
# print(f"P2 : {com}")
55+
return None
56+
elif c2 < c1 :
57+
if c2 == 2 and c1==3:
58+
com += 1
59+
print("Oops!...Best of luck next time.")
60+
return None
61+
elif c1 != 3:
62+
print("Oops!...Best of luck next time.")
63+
com += 1
64+
#print(f"P1 : {human}")
65+
return None
66+
else:
67+
human+=1
68+
print("Congratulations!...You Win.")
69+
# print(f"P2 : {com}")
70+
return None
71+
72+
#for desplaying result.
73+
def display_result(c1,c2):
74+
75+
print(f"You choose : {elements[c1-1]}")
76+
print(f"Computer choose : {elements[c2-1]}")
77+
78+
#validating the entered choice.
79+
def validate(num):
80+
if num < 0 or num > 3:
81+
num = int(input(("Enter the valid choice : ")))
82+
num = validate(num)
83+
84+
return num
85+
86+
#Calculating points.
87+
def points():
88+
print(f"Your Points :{human}")
89+
print(f"Computer Points :{com}")
90+
91+
#final result
92+
def final(p1,p2):
93+
if (p1 == 10 ):
94+
print(f"You win by {p1-p2}")
95+
elif (p2 == 10):
96+
print(f"You lose by {p2-p1}")
97+
return None
98+
# def get_choice():
99+
# human_choice : int(input("Enter the choice here 1-3 : "))
100+
# return human_choice
101+
102+
# def get_random():
103+
# com_choice = random.randint(1,3)
104+
# return com_choice
105+
106+
display_choices()
107+
i =30
108+
#loop for playing the match
109+
while(i < 40):
110+
if human == 10 or com == 10:
111+
i = 40
112+
print()
113+
final(human,com)
114+
else:
115+
print()
116+
play_game(human,com)

0 commit comments

Comments
 (0)