QUESTION

Your python code must provide the following:

  • Prompt the user for a region name.
  • Read the data from the file selecting only the data for the region.
  • Build three dictionaries for the region for the population, GDP, and personal income. The key for each dictionary is the State.
  • In the case where the user entered an invalid region, an appropriate error message should be displayed. Note, you will not know this until you've read through the file and found no data.
  • Write a function called calc_total_pop is passed the population dictionary and returns the total population. You will obviously need to iterate through the dictionary to produce the total population.
  • Write a function called calc_total_gdp that is passed the gdp dictionary and returns the total GDP.
  • Write a function called calc_total_pi that is passed the personal income dictionary and returns the total personal income.

The output of your must be as follows:

  • A list (not python list) of states in the region.
  • The Total population for the region.
  • The total GDP for the region.
  • The average population of the region.
  • The average personal income in the region.

Include any appropriate captions and labels to describe the above date. Below is a suggest output format. Points will be deducted for an untidy report.

Economic statistics for the Great_Lakes region:
States in Region: Illinois, Indiana, Michigan, Ohio, Wisconsin
Total population: 46.436 million
Average population: 9.2872 million
Total GDP: 1776.04 billion
Average PI: 37669.85

You may want to investigate the round function to reduce the number for decimals in floating point numbers. The join function will provide handy for showing all States on one line.

For easier debugging and clarity, use multiple cells to modularize your program. One model would be three cells where:

  • The first cell reads the file and builds the data structures.
  • The second cell performs the calculations.
  • The last cell displays the report

sample.txt

Alabama,Southeast,4.7848,153.84,162.2283,485,98.285,11.019
Alaska,Far_West,0.7141,43.47,32.6496,68,22.956,6.327
Arizona,Southwest,6.4108,221.02,217.7587,763,135.599,16.944
Arkansas,Southeast,2.9228,92.08,93.6831,405,56.79,7.507
California,Far_West,37.3344,1672.5,1579.1,9235,1009.6,133.61
Colorado,Rocky_Mountain,5.0485,230.98,210.6077,868,141,16.786
Connecticut,New_England,3.5766,197.61,197.8393,717,121.063,15.102
Delaware,Mideast,0.8998,55.5,36.9576,249,25.364,3.07
D.O.C,Mideast,0.605,89.97,42.2093,833,75.886,3.668
Florida,Southeast,18.846,650.29,725.4363,2522,399.293,69.981
Georgia,Southeast,9.7147,358.84,333.6327,1215,227.035,25.884
Hawaii,Far_West,1.3643,59.67,56.8272,276,37.876,5.449
Idaho,Rocky_Mountain,1.5708,50.73,50.3852,337,29.356,3.309
Illinois,Great_Lakes,12.8405,571.23,540.2233,2746,362.936,50.556
Indiana,Great_Lakes,6.4899,241.93,223.1581,898,144.024,17.475
Iowa ,Plains,3.0503,124.01,119.0797,1039,72.04,9.097
Kansas,Plains,2.8588,113.32,110.8847,777,71.431,9.03
Kentucky,Southeast,4.3467,141.98,143.211,484,92.351,12.327
Louisiana,Southeast,4.5441,200.94,169.1167,759,105.141,14.309
Maine,New_England,1.3276,45.56,49.3602,175,29.505,4.539
Maryland,Mideast,5.788,264.32,289.6531,1128,175.607,18.693
Massachusetts,New_England,6.5633,340.16,337.9316,1564,229.298,20.998
Michigan,Great_Lakes,9.8777,329.81,346.8182,1159,215.579,29.912
Minnesota,Plains,5.3107,240.42,226.3199,1327,154.014,18.851
Mississippi,Southeast,2.9691,85.36,91.5883,387,52.85,7.368
Missouri,Plains,5.9961,216.68,219.484,911,142.841,14.959
Montana,Rocky_Mountain,0.9907,31.92,34.2688,238,20.06,2.468
Nebraska,Plains,1.8297,80.64,73.0691,313,47.024,5.648
Nevada,Far_West,2.7038,109.61,99.2062,313,62.413,10.268
New_Hampshire,New_England,1.3168,55.24,59.1947,162,35.263,4.486
New_Mexico,Southwest,2.0648,70.79,68.4891,302,42.637,5.554
New_Jersey,Mideast,8.8034,431.41,449.0599,1733,267.585,42.41
New_York,Mideast,19.3992,1013.3,960.8265,6156,638.668,90.878
North_Carolina,Southeast,9.559,380.69,338.9875,1300,218.619,30.474
North_Dakota,Plains,0.6743,31.62,29.1538,603,18.645,2.366
Ohio,Great_Lakes,11.5383,413.99,418.5351,1608,272.716,33.551
Oklahoma,Southwest,3.7595,132.92,135.0626,448,80.058,9.231
Oregon,Far_West,3.8382,174.17,137.6717,703,88.9,8.032
Pennsylvania,Mideast,12.7113,493.53,529.8078,2125,323.795,39.317
Rhode_Island,New_England,1.0528,43.153,45.2676,200,27.112,3.971
South_Carolina,Southeast,4.6358,143.41,151.5368,472,93.025,11.875
South_Dakota,Plains,0.8162,34.37,33.1357,617,18.239,2.733
Tennessee,Southeast,6.3567,227.36,225.2247,730,138.683,19.039
Texas,Southwest,25.2427,1116.27,961.8281,2887,621.098,93.056
Utah,Rocky_Mountain,2.7751,105.2,90.1127,326,62.596,6.559
Vermont,New_England,0.626,23.34,25.1157,105,15.122,2.522
Virginia,Southeast,8.0251,377.47,359.9561,1113,248.951,28.016
Washington,Far_West,6.7436,307.69,286.7438,1526,187.423,28.482
West_Virginia,Southeast,1.854,53.58,58.9501,121,35.19,5.149
Wisconsin,Great_Lakes,5.6896,219.08,220.5023,973,141.446,18.435
Wyoming,Rocky_Mountain,0.5644,32,25.4336,82,15.684,3.662

Public Answer

EY0RBX The First Answerer