TLP - Programming Maintenance
Week 1 - Revisiting the FOP Final
Level
This assignment is considered a "required" coding assignment and is worth 2 points toward the code grade.
Background
To avoid mistakes, please read the following carefully.- Data files needed
- The functions for all four tasks should go in the same single file which you will submit to Autolab for grading.
- Each script will be submitted to Autolab:
- Autolab will return a score from 0-4 like it did on the final. This score will be converted to 0-2 to align with this course's grading.
During the final CD for Fundamentals of Programming you completed two parts - a written part and a programming part. Over the years I have discovered that some students do well on the programming part because it is all fresh and they studied hard. But by the time a month has passed they have largely lost their programmers "edge." On the flip side, I have seen plenty of people who panicked with the time pressure of the final and did very poorly in December, but, when given a chance to revisit the activity without the pressure, were suddenly able to figure it all out.
Because of that, I always begin this course by having you revisit (or repeat) the programs from the programming portion of the final. [To be accurate, I had three versions of the programming CD that varied on what they specifically asked for, although the general structure was identical for all three versions. This is the version given at the Community of Practice event. If you attended one of the three make-up CDs on zoom this will look comparable but slightly different.]
I would ask that you start this assignment from a blank slate. Do not simply resubmit your previous code if you got the 4. I know, that seems like "punishment." But I think there is benefit of working through the activity again when your brain is in a completely different space.
Task One
The problem with comparing athletes in a sport like basketball is that different players play different amounts of time. It is one thing to ask which is better:- 20 points having played 30 minutes of a game, or
- 10 points having played 10 minutes of a game.
- 38387 points in 57446 minutes vs
- 24815 points in 40597 minutes
- pointsPer48 = (Points Scored ÷ Minutes Played) x 48
Create a function called: pointsPer48()
This function should:
- Parameters:
- points scored – assumed to be an integer
- minutes played – assumed to be an integer
- Returns:
- An "adjusted" value (assumed to be a float) based on the formula above
- Note, do not round this value. Return as is.
- Data Files
- Example Run
- You may submit this to Autolab for grading even without the additional elements.
Task Two
Let's consider how many points the "average" NBA player scores in their career.
Create a function called: averagePoints()
This function should:
- Parameters:
- filename - a string presumed to be one of the two files provided or one with a similar structure.
- Returns:
- The average number of points scored by the players listed in the provided file.
- Note, do not round this value. Return as is.
- Data Files
- Example Run
- You may submit this to Autolab for grading even without the additional elements.
Task Three
In Task One I asked you to calculate, for one player, their pointsPer48 statistics. Let's use that function to add another column to our data files.
Create a function called: addColumn()
This function should:
- Parameters:
- input filename - a string presumed to be one of the two files provided or one with a similar structure.
- output filename - a string that will become the name of a new (previously nonexistent) file.
- Returns:
- Nothing
- Instead, it creates a new file with the name provided as the output filename parameter. This file is identical to the input file with the addition of a new column at the end containing the information calculated by the pointsPer48() function from Task One for that player.
- Data Files
- Example Run
- Example File Output
- You may submit this to Autolab for grading even without the additional elements.
Task Four
In Task Three I asked you to add some data to our file. But it added data for every player in our file. Suppose I want to focus in on the players who played the equivalent of a full NBA season (82 games). In this last function, I encourage you to copy and paste your code from addColumn() but rename it to be addAndClean(). Then modify the code so that it only writes out the information for players with 82 or more games to the final output file.
Create a function called: addAndClean()
This function should:
- Parameters:
- input filename - a string presumed to be one of the two files provided or one with a similar structure.
- output filename - a string that will become the name of a new (previously nonexistent) file.
- Returns:
- Nothing
- Instead, it creates a new file with the name provided as the output filename parameter.
- This file is mostly identical to the input file with two changes:
- There is a new column at the end containing the information calculated by the pointsPer48() function from Task One for that player. [Exactly task three]
- It only includes a row (player) if they have played in 82 or more games.
- This file is mostly identical to the input file with two changes:
- Data Files
- Example Run
- Example File Output
- Notice that Able, Love, and Stewart are not in this file because they did not play enough games.
- You may submit this to Autolab for grading even without the additional elements.