You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
print('Welcome to HANDCRICKET....\nThr program replicates the classic handcricket game....\nRules:\nFirst a toss is held .. if u win u are given the chance to bowl or bat..\nIf ur score is greater than that of computer..u lose\n')
12
+
13
+
defget_int(prompt):
14
+
whileTrue:
15
+
try:
16
+
value=int(input(prompt))
17
+
break
18
+
exceptValueError:
19
+
print("\nSorry, I didn't understand that.\n")
20
+
continue
21
+
22
+
returnvalue
23
+
24
+
whileTrue:
25
+
val=get_int('How many wickets u want in the game')
26
+
ifval<=0:
27
+
print('Enter either 1 or 0')
28
+
else:
29
+
break
30
+
31
+
wicket=copy.deepcopy(val)
32
+
whileTrue:
33
+
34
+
ov=get_int('How many overs U want in the game')
35
+
ifov<=0:
36
+
print('Over must be greater than 0')
37
+
else:
38
+
break
39
+
40
+
overs=copy.deepcopy(ov)
41
+
i=0
42
+
j=0
43
+
44
+
45
+
picked=get_int('Would You Pick Head or Tails \n [0] for heads , [1] for tails')
46
+
47
+
deftoss():
48
+
globalchosen
49
+
globalcompchoice
50
+
result=coin[random.randint(0 , 1)]
51
+
print(result)
52
+
ifcoin.index(result) ==picked:
53
+
print('\nYou Won The Toss')
54
+
chosen=choices[get_int('Would U Like To Bat Or Bowl , [0] for bat , [1] for bowl\n')]
55
+
print(f'\nYou chose to {chosen}\n')
56
+
57
+
else:
58
+
print('\nYou Lost The Toss...Computer Won')
59
+
chosen=choices[random.randint(0 , 1)]
60
+
61
+
print(f'\nComputer chose to {choices[choices.index(chosen)+1]}')
62
+
print(f'You Will {chosen}\n')
63
+
print()
64
+
65
+
66
+
defcheckSession():
67
+
globalsession
68
+
globaluser
69
+
globaldev
70
+
ifsession==1:
71
+
ifchosen=='bat':
72
+
ifuser>dev:
73
+
print(f'overs remaining {overs}\n')
74
+
print(f'You won ... Your end score was {user} ... Congrats..\nThanks for playing\n')
75
+
sys.exit()
76
+
else:
77
+
ifdev>user:
78
+
print(f'overs remaining {overs}\n')
79
+
print(f'You Lost ... Computer Won....Your end score was {user}\n')
80
+
sys.exit()
81
+
82
+
ifsession==2:
83
+
ifuser>dev:
84
+
print(f'overs remaining {overs}\n')
85
+
print(f'You won ... Your end score was {user} ... Congrats..\nThanks for playing\n')
86
+
sys.exit()
87
+
elifuser<dev:
88
+
print(f'overs remaining {overs}\n')
89
+
print(f'You Lost ... Computer Won....Your end score was {user}\n')
90
+
sys.exit()
91
+
92
+
93
+
94
+
95
+
96
+
defhandcricket():
97
+
globali
98
+
globalwicket
99
+
globaluser
100
+
globaldev
101
+
globalsession
102
+
globalchosen
103
+
globalovers
104
+
globalj
105
+
globalval
106
+
globalov
107
+
j+=1
108
+
ifovers<ovorj!=1:
109
+
i+=1
110
+
checkSession()
111
+
ifovers==0 :
112
+
113
+
i=-1
114
+
session+=1
115
+
ifsession==2:
116
+
checkSession()
117
+
overs=copy.deepcopy(ov)
118
+
wicket=copy.deepcopy(val)
119
+
ifchosen=='bat':
120
+
chosen='bowl'
121
+
print('\n\nEnd of Innings\n\nEnd of Batting...Get ready to bowl\n\n')
122
+
123
+
print(f'Your Score is {user}\nComputers score is {dev}\n')
124
+
elifchosen=='bowl':
125
+
chosen='bat'
126
+
print('\n\nEnd of innings\n\nEnd of Bowling...Get ready to bat\n\n')
127
+
print(f'Your score is {user}\nComputers score is {dev}\n')
128
+
129
+
handcricket()
130
+
131
+
ifi//6==1:
132
+
overs-=1
133
+
i=-1
134
+
print(f'End of one over , remaining {overs}\n')
135
+
handcricket()
136
+
137
+
138
+
139
+
ifwicket==0:
140
+
session+=1
141
+
print(f'All wickets are gone\n{overs} overs were remaining\n')
142
+
ifsession==2:
143
+
checkSession()
144
+
145
+
overs=copy.deepcopy(ov)
146
+
i=-1
147
+
wicket=copy.deepcopy(val)
148
+
ifchosen=='bat' :
149
+
print('\n\nEnd of innings\n\nEnd of Batting...Get ready to bowl\n\n')
150
+
151
+
print(f'Your Score is {user}\nComputers score is {dev}\n')
152
+
chosen='bowl'
153
+
handcricket()
154
+
155
+
156
+
elifchosen=='bowl':
157
+
print('\n\nEnd of innings\n\nEnd of Bowling...Get ready to bat\n\n')
158
+
print(f'Your score is {user}\nComputers score is {dev}\n')
159
+
chosen='bat'
160
+
handcricket()
161
+
162
+
163
+
164
+
165
+
player=get_int('Chose a number from 1 to 6\n')
166
+
ifplayer>6orplayer<1:
167
+
print('number must be greater than one and smaller than 6 \n')
168
+
i-=1
169
+
handcricket()
170
+
print(f'You Chose {player}\n')
171
+
comp=random.randint(1 , 6)
172
+
print(f'Computer Chose {comp}\n')
173
+
174
+
175
+
176
+
ifplayer==comp:
177
+
wicket-=1
178
+
print('wicket\n')
179
+
ifchosen=='bat':
180
+
print(f'You lost a wicket , remaining wickets = {wicket}\n Ur Score is {user}\n')
181
+
handcricket()
182
+
else:
183
+
print(f'Computer Lost a wicket , remaining {wicket}\n')
print('Hello....Welcome to HANGMAN.. \nThe rules here are simple...\nu are given a random word...\nu have to guess the word by guessing a alphabet in the word... \nFailing 6 times will result the game to be over \nLets begin \n ')
0 commit comments