Cricket Game
Cricket Game
Instructions:
3. While batting, if the number selected by you and computer is different, then your number will add
to your runs.
If the number selected by you and computer is same, then you will lose your wicket.
4. While bowling, if the number selected by you and computer is different, then the computer's
number will add to its runs.
If the number selected by you and computer is same, then the computer will lose its wicket.
5. Each player will get 2 wickets and 2 overs (12 balls) for batting and bowling.
6. The innings will end after either the three wickets fell or the overs end.
import random
# Toss
u_opt = 0
c_opt = 0
if random_toss == 1 and toss == "heads":
else:
if random_opt == 1:
c_opt = "bat"
elif random_opt == 2:
c_opt = "ball"
# First Innings
runs_1 = 0
wickets_1 = 0
balls_1 = 0
else:
if u_choice == c_choice:
wickets_1 += 1
else:
Bat_first = "You"
Ball_first = "Computer"
runs_1 += u_choice
Bat_first = "Computer"
Ball_first = "You"
runs_1 += c_choice
print("\nScore =",runs_1,"/",wickets_1)
balls_1 += 1
if balls_1 == 6:
print("\nFinal Score:")
print("Runs =",runs_1)
print("wickets =",wickets_1)
# Second Innings
runs_2 = 0
wickets_2 = 0
balls_2 = 0
c_choice = random.randint(1,6)
else:
if u_choice == c_choice:
wickets_2 += 1
else:
if Bat_first == "Computer":
runs_2 += u_choice
Bat_second = "You"
runs_2 += c_choice
Bat_second = "Computer"
print("\nScore =",runs_2,"/",wickets_2)
balls_2 += 1
if balls_2 == 6:
print("\nFinal Score:")
print("Runs =",runs_2)
print("wickets =",wickets_2)
# Result of Match
print("\n~~~~~~~~~~ Result ~~~~~~~~~~")
if Bat_first == "You":
else:
print("\nBetter luck next time! The Computer won the Match by",runs_1 - runs_2,"runs.")
if Bat_second == "You":
else:
print("\nBetter luck next time! The Computer won the Match by",2 - wickets_2,"wickets.")
else: