Intro to Computer Science
Homework #6
CSV Files!
Code due by Monday, October 28th at 11:59:59pm
Late code may be submitted up to two days late for a penalty of 10% per day.
Introduction
My friend is a really big geography buff. He loves statistics about the various states and countries. Recently we were having an interesting discussion about which states were the most and least populous by size. That got us interested in calculating various popluation densities. For this assignment you will write the code to answer this question.
Specifics
In a file called: hw06.py
Create a program that should:
- Ask for two inputs:
- Ask for the name of the input file.
- Ask for the name of the output file that your code will produce.
- Prints:
- 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 into the output csv file
- Closes both files
- Data files to use:
- Example run of the program:
Note: This means I need to be able to OPEN whatever file name I want. Do NOT hardcode "StateData.csv" into your open call. Instead, ask for a file name with input (say input_filename), and then open it in your program like this:
fin = open(input_filename,"r")
- Example output using the StateData.csv input file:
- Example output using the StateData.csv input file in a text editor:
Hint: You may want to open the csv files with notepad or textedit to make sure things are right (e.g. you have commas where you need them, the data goes on multiple rows, etc.).
Final Submission
Use the program submission system to upload your code.