Graded Problem Set #3.3
File Problem
Background
This activity should be completed on your own. Unlike the practice problems, where you are allowed, and even encouraged, to talk about the process with your classmates, these should be attempted on your own. If you have difficulty with these, please reach out to me for assistance or guidance.
These problems will be completed using an editor such as Thonny or IDLE and submitted to Autolab for grading.
Activity
My son is a really big geography buff. He loves statistics about the various states and countries. We were having an interesting discussion about which states were the most and least populous by size. That got us interested in calculating various population densities. For this assignment you will write the code that we produced together (And yes. I wrote this code with my then 10 year old son).
Program Guide
For this assignment you should create the following function in a file called populations.py
Create a function called: addDensities()
This function should:
- Parameters:
- input file name - (you may use any of the three files below for testing)
- output file name
- Returns:
- Nothing
- Actions:
- Opens the input file
- Opens the output file
- Pulls off the header and adds one more column labeled "Density"
- For each territory provided in the data file you opened:
- extract population and size
- calculate population density (people per square area)
- writes the original data PLUS the population density
- Closes both files
- Data Files
- Example Run
- Example Output