-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcricket.py
129 lines (127 loc) · 4.19 KB
/
cricket.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
import time,random
k=0
print("---------------------------------Welcome to the Game of Cricket------------------------------")
def main():
Players=[]
for i in range(1,3):
Players.append(input(f"Enter player{i} name\n"))
overs = int(input("Enter number overs\n"))
print("-----------------Toss starts in 10 seconds 😍------------------")
for i in range(10,0,-1):
print("\r"+str(i))
time.sleep(1)
print(f"Coin is in the hands of {Players[0]}")
time.sleep(1)
a = random.choice(['Heads', 'Tails'])
print(f"{a} is the call")
time.sleep(1)
b = random.choice(['Heads','Tails'])
print(f"{b} ups")
time.sleep(1)
if a==b:
print(f"{Players[1]} wins the toss")
time.sleep(1)
c = random.choice(['Bat','Bowl'])
print(f"and choose to {c} first")
if c=='Bat':
t=Players[1]
else:
t=Players[0]
else:
print(f"{Players[0]} wins the toss")
time.sleep(1)
c = random.choice(['Bat','Bowl'])
print(f"and choose to {c} first")
if c=='Bat':
t=Players[0]
else:
t=Players[1]
time.sleep(1)
print(f"-----------------------{t.upper()} is on the strike---------------------------")
time.sleep(1)
runs = score1 = 0
for i in range(overs):
x = random.randint(1,6)
for j in range(1,7):
input("Press Enter to Bowl")
if j==x:
out = random.choice(['Yes','No'])
if out=='Yes':
x=0
print("HOWZZZATTT!!!!!!!!!!!!!!!")
time.sleep(1)
break
runs = random.randint(0,6)
if runs == 4:
print("Brilliant! It\'s a Four")
time.sleep(1)
if runs == 6:
print("Hurray!!! Great it\'s a Six")
time.sleep(1)
score1 = score1 + runs
print(f"score = {score1}")
if j==6:
print(f"Over = {str(i+1)+'.'+str(0)}")
else:
print(f"Over = {str(i)+'.'+str(j)}")
time.sleep(1)
if x==0:
print(f"{t} got out on {score1}")
break
if t==Players[0]:
l=Players[1]
else:
l=Players[0]
time.sleep(1)
print(f"-----------------------Now {l.upper()} is on the strike---------------------------")
time.sleep(1)
runs = score2 = 0
for i in range(overs):
x = random.randint(1,6)
for j in range(1,7):
input("Press Enter to Bowl")
if j==x:
out = random.choice(['Yes','No'])
if out=='Yes':
x=0
print("HOWZZZATTT!!!!!!!!!!!!!!!")
time.sleep(1)
break
runs = random.randint(0,6)
if runs == 4:
print("Brilliant! It\'s a Four")
time.sleep(1)
if runs == 6:
print("Hurray!!! Great it\'s a Six")
time.sleep(1)
score2 = score2 + runs
print(f"score = {score2}")
if j==6:
print(f"Over = {str(i+1)+'.'+str(0)}")
else:
print(f"Over = {str(i)+'.'+str(j)}")
time.sleep(1)
if x==0:
print(f"{l} got out on {score2}")
break
time.sleep(1)
print("---------------------------------Results of the Match---------------------------------------------")
if score2>score1:
print(f"{l.upper()} WON THE MATCH BY {score2 - score1} run")
elif score1>score2:
print(f"{t.upper()} WON THE MATCH BY {score1 - score2} run")
else:
print(f"MATCH TIED AT A SCORE OF {score2}")
while 1:
if k==0:
k=1
main()
else:
print("Do you wanna play again ?")
a = input("------------------press 1 for Yes or 0 for No--------------------\n")
if a=='1':
main()
elif a=='0':
exit()
else:
print("Wrong input")