0% found this document useful (0 votes)
167 views2 pages

Batting Points Calculation in Python

This document provides a scenario for assigning points to cricket players in a match to determine the "Man of the Match". It describes rules for calculating points for batting, bowling, and fielding based on runs scored, wickets taken, catches made etc. It then provides sample player data and asks to write a Python program to calculate points for each player using functions defined in a module, and output the highest scoring player. Hints are provided on how to approach the problem by defining variables, converting rules to expressions, defining functions, and using them in the main program.

Uploaded by

Vishal Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views2 pages

Batting Points Calculation in Python

This document provides a scenario for assigning points to cricket players in a match to determine the "Man of the Match". It describes rules for calculating points for batting, bowling, and fielding based on runs scored, wickets taken, catches made etc. It then provides sample player data and asks to write a Python program to calculate points for each player using functions defined in a module, and output the highest scoring player. Hints are provided on how to approach the problem by defining variables, converting rules to expressions, defining functions, and using them in the main program.

Uploaded by

Vishal Kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Module 3 Assignment 

Introduction
For this assignment, read the scenario below and then respond to the problem statement 
described. 

Scenario
The 'Man of the Match' award of a 50-over cricket match is decided by computing points 
earned by players. The points are calculated on the basis of the following rules:  

Batting
● 1 point for 2 runs scored 
● Additional 5 points for a half-century 
● Additional 10 points for a century 
● 2 points for strike rate (runs/balls faced) of 80-100 
● Additional 4 points for strike rate>100 
● 1 point for hitting a boundary (four) and 2 points for over boundary (six) 

Bowling
● 10 points for each wicket 
● Additional 5 points for three wickets in innings  
● Additional 10 points for 5 wickets or more in innings 
● 4 points for economy rate (runs given per over) between 3.5 and 4.5 
● 7 points for an economy rate between 2 and 3.5 
● 10 points for an economy rate less than 2 

Fielding
● 10 points each for catch/stumping/run out 

The performance of each player is stored in a dictionary object. Displayed below is data for 5 
players.  

p1={​'name'​:​'Virat Kohli'​, ​'role'​:​'bat'​, ​'runs'​:112, ​'4'​:10, ​'6'​:0,


'balls'​:119, ​'field'​:0}

p2={​'name'​:​'du Plessis'​, ​'role'​:​'bat'​, ​'runs'​:120, ​'4'​:11, ​'6'​:2,


'balls'​:112, ​'field'​:0}

p3={​'name'​:​'Bhuvneshwar Kumar'​, ​'role'​:​'bowl'​, ​'wkts'​:1, ​'overs'​:10,


'runs'​:71,​ 'field'​:1}

p4={​'name'​:​'Yuzvendra Chahal'​, ​'role'​:​'bowl'​, ​'wkts'​:2, ​'overs'​:10,


'runs'​:45,​ 'field'​:0}

p5={​'name'​:​'Kuldeep Yadav'​, ​'role'​:​'bowl'​, ​'wkts'​:3, ​'overs'​:10, ​'runs'​:34,


'field'​:0}
 

Programming with Python 


Module 3 Assignment 

Problem Statement
Assuming that these are the top 5 performers, write a Python program to decide the player 
with the highest points. Develop separate functions to compute batting and bowling points 
and save them in a module. These functions should be imported into the main code.   

Assignment Submission
Your submission should have a fully functional code with: 

1. One module containing the required functions. 


2. One script file with the main code which computes the top player amongst the 5 given 
players.  

When your script is run, it should generate a result which might look like this: 

{'name': 'Virat Kohli', 'batscore': 83}


{'name': 'du Plessis', 'batscore': 94}
{'name': 'Bhuvneshwar Kumar', 'bowlscore': 10}
{'name': 'Yuzvendra Chahal', 'bowlscore': 24}
{'name': 'Kuldeep Yadav', 'bowlscore': 42}
>>>

Hint
The calculation of points will require conditional logic to be applied. Since this is to be 
performed for 5 players, there’s looping involved. Defining and calling functions from a 
module is also required.  

You can approach this assignment in the following sequence:  

1. First, create the required variables.  


2. Next, convert the rules into expressions and conditions. For example, points = runs/2 
or if runs >50, points = points+2 and so on. 
3. Next, define each of the two functions for batting or fielding and bowling. 
4. Finally, write your program using the conditions and the functions. 

Learning outcomes being evaluated


● Use conditional logic in Python programs 
● Write programs using conditionals, loops, iterators and generators, functions and 
modules and packages. 
 

Programming with Python 

Common questions

Powered by AI

Bowling points are calculated by awarding 10 points per wicket, with an additional 5 points for taking three wickets in an innings, and an extra 10 points for five wickets or more. Points also hinge on the economy rate, adding 4 points for rates between 3.5 and 4.5, 7 points between 2 and 3.5, and 10 points for less than 2. These conditions ensure achievements like a three-wicket haul notable affects a player's score by adding a flat increment to the base points, reflecting the player's performance impact .

Fielding points acknowledge the significance of contributions outside traditional batting and bowling roles. The document awards 10 points each for catches, stumpings, and run-outs, recognizing fielding's impact on match outcomes. These metrics ensure that a player's all-round contribution to the game is accounted for, providing a holistic view of their performance, potentially influencing their chance to be 'Man of the Match' .

Implement Python functions to compute batting and bowling points per the assignment rules. Define functions that accept player data, compute points based on conditions like runs and strike rates for batsmen, and wickets and economy rates for bowlers. Utilize these functions to process player data dictionary, storing results. Conclude by looping through computed scores to determine the player with the highest aggregate points, showcasing modular functionality and clear separation between computing logical processes and I/O operations .

Modularizing functions enable separation of concerns—the distinct rules and calculations of batting and bowling are handled independently, allowing each to be coded, tested, and maintained separately. This modular approach enhances code readability, facilitates easier debugging, and allows for reuse across different scripts or extensions of the program. By maintaining clear boundaries, the program becomes adaptable for further inclusion of fielding or additional game metrics if needed .

The point system assigns varying weightings to batting, bowling, and fielding. Batting points encompass runs, milestones, and strike rates, reflecting tactical prowess. Bowling rewards include wickets and economy rate—quantifying control and impact—while fielding offers flat points per action. The system attempts to balance these facets, yet disparities may exist where dominant individual performances overemphasize one aspect. For instance, scores heavily favor run-scorers or wicket-takers while consistently ignoring routine fielding unless it leads to wicket-saving results, indicating potential imbalance in holistic performance assessment .

Loops are essential to iterating through each player's data to compute and aggregate points systematically. Rather than executing calculations manually for each player, loops automate this process, applying consistent logic across all entries. Tasks such as iterating through players to calculate their batting, bowling, and fielding scores efficiently leverage the DRY principle (Don't Repeat Yourself), thereby reducing redundancy and the potential for errors .

Dictionaries provide a structured way to store player-specific performance metrics, allowing for efficient key-value pair access. They influence program organization by encapsulating each player's data within an accessible unit, combining related data types (e.g., runs, wickets, fielding actions). This structure facilitates conditional checks and specialized function operations over player attributes, supporting dynamic adjustments and expansions when new roles or metrics are introduced. Their use enhances quick retrieval and manipulation, promoting more effective code execution .

The process involves writing a Python program with separate functions to compute batting and bowling points, residing in a module. These functions calculate points based on described rules—for instance, tally batting points for players like 'Virat Kohli' based on runs, boundaries, and strike rates. Similarly, compute bowling points for players like 'Bhuvneshwar Kumar' based on wickets and economy rate. The main script imports these functions to compute and compare scores, determining the player with the highest points via conditional logic and looping through player data .

Batting points are calculated by awarding 1 point for every 2 runs scored, additional 5 points for a half-century, and additional 10 points for a century. Points are also given for strike rates—with 2 points for a strike rate between 80-100, and an additional 4 points for a strike rate over 100. Moreover, 1 point is awarded for every boundary (four) hit and 2 points for every over boundary (six).

Challenges such as incorrect data types or missing keys might occur with dictionaries. For instance, attempts to access a non-existent key would raise an error. Mitigation strategies include validating input data before processing, using try-except blocks to handle exceptions gracefully, and utilizing methods like .get() that allow specifying default values if a key is absent. Moreover, data consistency can be enforced through controlled data entry processes .

You might also like