Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(use python)This program will read multiple basketball players data from a file. The program then calculates some statistical data and display them on the screen.

(use python)This program will read multiple basketball players data from a file. The program then calculates some statistical data and display them on the screen. The program requires from you to design several functions, where one the functions opens and reads the files contents and then it stores these data as a list of Strings (Each String represents information about one player). This list need to be processed later one using other functions in order to find and calculate several statistical data (The shooting percentages and the number of points per 48 minutes, the totals of players statistical values and other data).

WHAT DO YOU NEED TO USE?

In this program you are expected to use the following topics that we learned in this class:

Function (to break the program into smaller tasks)

Reading from a file

List operations

String Operations

Building mathematical equation

Using selection (if) statement.

Using loop.

Exception Handling

THE FILE THAT CONTAINS THE DATA

image text in transcribed

This table shows the content of the file that contains the data. The file is saved next to this document on the class webpage.

CODING PHASE

Go back to your file that you made in the previous phase and start to inset a python code between the lines of design you came up with. Your code should define and use the following function.

A function called ExtractDataFromAfile that does not take any parameters and it returns back 2 values: A Boolean value and a list of Strings. The function tries to open a file that contains players information (the file name and its contents are provided on the class webpage next to this document). If the opening and reading operation done without any problems (Exceptions) then return back True and a list of Strings that contains the player information. Otherwise, return back False and an empty list.

You are trying to write a code that opens a file. There is a good chance that this process could generate a run time error for several reasons. You have to write a code that use the exception handling technique to forbid such error and show a proper message.

A function called ProcessFileData that takes one parameter which is a list of Strings and it does not return back anything. The function simply controls the operations of processing players information. The function perform its operations as follow:

1. First, define the following parallel empty Lists:

a) A list to store the Players uniform number.

b) A list to store the Players full name (first followed by last).

c) A list to store the Players Minutes played.

d) A list to store the Players Field goal attempts (number of shots taken)

e) A list to store the Players Field goals made (number of baskets made)

f) A list to store the Players Three Point Attempts (3pt shots A list to store the Players attempted included in fga)

g) A list to store the Players Three Pointers Made (3pt baskets made include in fgm)

h) A list to store the Players Free Throw attempts (number of foul shots taken)

i) A list to store the Players Free Throws Made (number of foul shots made)

j) A list to store the Players Offensive rebounds (rebounds of teams missed shots)

k) A list to store the Players Defensive rebounds (rebounds of opponents missed shots)

l) A list to store the Players Steals (number of times a player forced an opponent turnover)

m) A list to store the Players Blocked Shots

n) A list to store the Players Assists (number of times a players pass resulted in a basket)

o) A list to store the Players Turnovers

p) A list to store the Players Personal Fouls

2. Now, iterate over the elements of the parameter list one by one (One item (player information) per iteration).

a) For every item, you need to store your current player information (Which is a String (One line from a file)) into a variable called CurrentPlayer.

b) Use the variable from the step 2.a in addition to the parallel lists (a-c (inclusive)) defined in step 1 as arguments when you call the function getBasicPlayerInfo.

c) Use the variable from the step 2.a in addition to the parallel lists (d-i (inclusive)) defined in step 1 as arguments when you call the function getShooting.

d) Use the variable from the step 2.a in addition to the parallel lists (j-k (inclusive)) defined in step 1 as arguments when you call the function getRebounds.

e) Use the variable from the step 2.a in addition to the parallel lists (l-p (inclusive)) defined in step 1 as arguments when you call the function getOthers.

3. After you finish the loop, call the function ShowBasicPlayersInfo and send to it as arguments all the lists defined in step 1.

4. Call the function ShowAdvancePlayersInfo

A function called getBasicPlayerInfo that takes 4 parameters which are: A String, List of integers, List of String, List of integers and it does not return back anything. The first parameter is a string that represents the player current information. You need to process (make an operation over) this parameter to generate data that can be used to populates (adds) values to the 3 lists. The other 3 parameters are the lists of:

Players uniform number

Players full name (first name and last name)

Minutes played

A function called getShooting that takes 7 parameters which are: String, List of integers, List of integers, List of integers, List of integers, List of integers, List of integer) and it does not return back anything. This function processes the String parameters and then it populates (adds) to the 6 lists the values for the players shooting statistics:

Field goal attempts (number of shots taken)

Field goals made (number of baskets made)

Three Point Attempts (3pt shots attempted included in fga)

Three Pointers Made (3pt baskets made include in fgm)

Free Throw attempts (number of foul shots taken)

Free Throws Made (number of foul shots made)

A function called getRebounds that receives 3 parameters, a String and 2 integer lists and it does not return back anything. This function processes the String parameters and then it populates (adds) to these 2 lists the values for the players rebounding statistics:

1. Offensive rebounds (rebounds of teams missed shots)

2. Defensive rebounds (rebounds of opponents missed shots)

A function called getOthers that receives 6 parameters, a String and 5 integer lists parameters and it returns back nothing. This function processes the String parameters and then it populates (adds) to these 5 lists the values for the miscellaneous players statistics:

1. Steals (number of times a player forced an opponent turnover)

2. Blocked Shots

3. Assists (number of times a players pass resulted in a basket)

4. Turnovers

5. Personal Fouls

A function called ShowBasicPlayersInfo that receives 16 parameters and it returns back nothing. This function processes the parameter lists to calculate and show an output that looks like the following .

image text in transcribed

The function performs the following calculations to show some results.

Field Goal = Field Goals Made / Field Goals Attempted

(The result represents a percentage)

Three Point = Three Pointers Made / Three Pointers Attempts

(The result represents a percentage)

Free Throw = Free Throws Made / Free Throws Attempted

(The result represents a percentage)

Totals Rebounds = Offensive Rebounds + Defensive Rebounds

Points = (2 * Field Goals Made) + Three Pointers Made + Free Throws Made

Points Per 48 = Points / (Minutes Played / 48)

Some of your calculation above requires from you to perform division operations. There is a chance that the denominator is 0 which yields to a run time error. You have to write a code that use the exception handling technique to forbid such error and show a proper message.

Advance Functions

Define a function called PlayerOffensiveRating that finds and returns back the offensive rating of a player using the formula:

Offensive Rating = Points per 48 + (Offensive Rebounds per 48 * .4) + (Assists per 48 * .4) (Turnovers per 48 * .4)

Where you can calculate:

o Points Per 48 = Points / (Minutes Played / 48)

o Offensive Rebounds Per 48 = Offensive Rebounds / (Minutes Played / 48)

o Assists Per 48 = Assists / (Minutes Played / 48)

o Turnovers Per 48 = Turnovers / (Minutes Played / 48)

Do you know what the parameters that needed to be sent here are? I will let discover that.

Define a function called PlayerDefensiveRating that finds and returns back the defensive rating of a player using the formula:

Defensive Rating = (Defensive Rebounds per 48 * .4) + (Blocked Shots per 48 * .4) (Steals per 48 * .4) Personal Fouls per 48 Where you can calculate:

o Defensive Rebounds Per 48 = Defensive Rebounds / (Minutes Played / 48)

o Blocked Shots Per 48 = Blocked Shots / (Minutes Played / 48)

o Steals Per 48 = Steals / (Minutes Played / 48)

o Personal Fouls Per 48 = Personal Fouls / (Minutes Played / 48)

Do you know what the parameters that needed to be sent here are? I will let discover that.

Define a function called PlayerRating that finds and returns back the player rating using the formula:

PlayerRating = (Defensive Rating * .67) + (Offensive Rating * .33)

Where you can use the following formulas to get the needed data:

o Offensive Rating = Points per 48 + (Offensive Rebounds per 48 * .4) + (Assists per 48 * .4) (Turnovers per 48 * .4)

o Defensive Rating = (Defensive Rebounds per 48 * .4) + (Blocked Shots per 48 * .4) (Steals per 48 * .4) Personal Fouls per 48

Define a function called findTopOffensivePlayer that finds and returns back the name of the player who has the highest offensive rating using the formula defined in the previous page.

Do you know what the parameters that needed to be sent here are? I will let discover that.

Define a function called findTopDefensivePlayer that finds and returns back the name of the player who has the highest defensive rating using the formula defined in the previous page.

Do you know what the parameters that needed to be sent here are? I will let discover that.

Define a function called findMostValuablePlayer that finds and returns back the name of the player who has the highest MVP rating using the formula used inside the function PlayerRating.

Do you know what the parameters that needed to be sent here are? I will let discover that.

Define a function called ShowAdvancePlayersInfo that shows an output that look like this:

image text in transcribed

To verify your calculation and results so it matches the outputs here. Here is the full results.

image text in transcribed

WRAP YOUR WORK

Your final program should be as follows:

Make sure that every variable that you will use will have a proper name which reflects its task (This name should not be one character).

Your program must be documented. Use meaningful multi-character variable names. You must have a header (prolog). Your code appears between the design steps. Your program must have a main function and call Top Offensive Player: 23 Michael Jordan Top Defensive Player: 6 Bill Russell Most Valuable Player: 33 Kareem Abdul-Jabaar it to run the program. Your program has NO global code except for the import statement(s).

99 George Mikan 379 179 72 0 0 81 62 58 86 0 0 19 0 42

33 Kareem Abdul-Jabbar 448 252 145 0 0 72 63 67 101 13 23 46 26 29

32 Magic Johnson 363 163 86 5 1 89 77 17 55 19 4 123 43 21

12 Oscar Robertson 441 200 104 0 0 118 100 38 60 26 1 104 31 19

6 Bill Russell 434 149 79 0 0 59 36 97 145 16 29 42 23 30

23 Michael Jordan 411 287 138 31 12 122 105 18 39 33 17 61 31 34

33 Larry Bird 390 188 99 25 11 62 56 23 77 18 9 68 30 26

6 Julius Erving 451 236 119 14 5 84 67 43 74 26 20 58 38 32

44 Jerry West 343 163 89 5 2 99 87 7 35 39 2 143 23 11

24 Rick Barry 398 255 131 30 9 103 95 9 53 26 7 62 23 22

UN FN LN MP FGA FGM 3PA 3PM FTA FTM OR DR SB A T PF GeorgeMikan 379 179 72 0 448 252 145 0 81 62 58 86 0 0 19 0 42 72 63 67 101 13 23 46 26 29 33 Kareem Abdul- Jabbar 32 Magic Johnson 363 163 86 5 1 89 77 17 55 19 4 123 43 21 12 Oscar Robertson 441 200 104 0 0 118 100 38 60 26 1 104 31 19 6 Bill 23 Michael Jordarn 33 Larry Bird 6 Julius Erving 44 Jerry West 24 Rick Russell 434 149 79 0 0 59 36 97 145 16 29 42 23 30 411 287 138 3112 122 105 18 39 33 17 61 31 34 390 188 99 25 11 6256 23 7718 968 30 26 451 236 119 14 5 343 163 89 5 2 9987 7 35 39 2143 23 11 398 255 131 30 9 84 67 43 74 26 20 58 38 32 Barry 103 95 9 53 26 7 62 23 22 UN FN LN MP FGA FGM 3PA 3PM FTA FTM OR DR SB A T PF GeorgeMikan 379 179 72 0 448 252 145 0 81 62 58 86 0 0 19 0 42 72 63 67 101 13 23 46 26 29 33 Kareem Abdul- Jabbar 32 Magic Johnson 363 163 86 5 1 89 77 17 55 19 4 123 43 21 12 Oscar Robertson 441 200 104 0 0 118 100 38 60 26 1 104 31 19 6 Bill 23 Michael Jordarn 33 Larry Bird 6 Julius Erving 44 Jerry West 24 Rick Russell 434 149 79 0 0 59 36 97 145 16 29 42 23 30 411 287 138 3112 122 105 18 39 33 17 61 31 34 390 188 99 25 11 6256 23 7718 968 30 26 451 236 119 14 5 343 163 89 5 2 9987 7 35 39 2143 23 11 398 255 131 30 9 84 67 43 74 26 20 58 38 32 Barry 103 95 9 53 26 7 62 23 22

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions