TLP - Programming Maintenance
Week 1 - Revisiting the FOP Final
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 indicating how many of the four parts/tasks below are working properly.
As you may recall, we had to cancel the final CoP event in FOP due to weather. The PLAN for that CoP had been to take a two part final - a written part (something you still competed) and a programming part (something you did not). This activity looks at that programming part. BUT, it is worth stating that this activity would have been assigned this semester even if we had had that final. I think that this is a solid way to kick off the programming part of this course.
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 normally begin this course by having students revisit (or repeat) the programs from the programming portion of the final. Of course, this semester, it isn't repetition. It's all fresh.
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.