Cricket Score Python Automation Description
Cricket Score Python Automation Description
"""
class Player:
def __init__(self, runs, balls, sixes, fours, player_id, position):
self.runs = runs
self.balls = balls
self.sixes = sixes
self.fours = fours
self.player_id = player_id
self.position = position
def dotBalls(self):
self.balls += 1
class Team:
def __init__(self, overs, players: Player):
self.overs = overs
self.players = players
if balls == 0:
print(f"Overs : {over}")
else:
print(f"Overs : {over}.{balls}")
p1 = players.pop(0)
p2 = players.pop(0)
strike = p1
wickets = 0
print(f"\nOver: {over}")
if ball in "0123456":
strike.set_runs(int(ball))
strike.dotBalls()
score += int(ball)
if id(strike) == id(p1):
p1 = strike
if int(ball) % 2:
strike = p2
else:
p2 = strike
if int(ball) % 2:
strike = p1
balls -= 1
elif ball == "W":
wickets += 1
strike.dotBalls()
scorecard[strike.position] = strike
if id(strike) == id(p1):
p1 = strike
if players:
p1 = players.pop()
strike = p1
else:
scorecard[p2.position] = p2
self.print_scorecard(scorecard, score, over, (6 -
balls) + 1, p2.position, -1, wickets)
return score, wickets
else:
if players:
p2 = players.pop()
strike = p2
else:
scorecard[p1.position] = p1
self.print_scorecard(scorecard, score, over, (6 -
balls) + 1, p1.position, -1, wickets)
return score, wickets
balls -= 1
if other_team_score:
# print(f"other team score: {other_team_score}")
# # print(f"score: {score}")
if score > other_team_score:
self.print_scorecard(scorecard, score, over, 0,
p1.position, p2.position, wickets)
return score, wickets
if id(strike) == id(p1):
p1 = strike
strike = p2
else:
p2 = strike
strike = p1
scorecard[p1.position] = p1
scorecard[p2.position] = p2
def start_match():
players = int(input("Players: "))
overs = int(input("Overs: "))
t = Team(overs=overs, players=players)
team1 = t.match_innings(team_number=1, other_team_score=None)
team2 = t.match_innings(team_number=2, other_team_score=team1[0])
if team1[0] > team2[0]:
print(f"\nTeam 1 won the match by {team1[0] - team2[0]} runs!")
elif team1[0] < team2[0]:
print(f"\nTeam 2 won the match by {team2[0] - team1[0]} runs!")
else:
print(f"Match is Draw with runs: {team1[0]}")
if __name__ == "__main__":
start_match()