Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  • 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:
  • 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 into the output csv file
  • Closes both files
  • Data files to use:
  • SmallData.csv
  • StateData.csv
  • CountryData.csv
  • 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:

image text in transcribedimage text in transcribed
\fFile Edit Format View Help State, Population, Area (5q Miles) , Density Alabama, 4833722, 50744, 95. 25701560775659 Alaska, 735132, 571951. 26, 1. 2853053247928854 Arizona, 6626624, 113634.57, 58. 315211647300636 Arkansas , 2959373, 52068.17, 56.83650875381255 California, 38332521, 155959.34, 245. 78535020730405 Colorado, 5268367, 103717.53,50.795338068694846 Connecticut, 3596080, 4844.8, 742 .2556142668428

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

Students also viewed these Programming questions