Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

defmain()Your main algorithm will be as follows calling the above functions. 1. Call open_file to open an input file for reading 2. Call read_file to

defmain()Your main algorithm will be as follows calling the above functions. 1. Call open_file to open an input file for reading 2. Call read_file to read the desired data into a master list of tuples. 3. Display a menu of options and prompt for input (use the display_options

function to display the menu). 4. Loop until the input is " q "

Based on the input:

a) If option is '1', Call state_average_income to determine the average

median income for a state; display it. Your code should prompt the user to input a 2-letter code. If it is valid (if it is one of the codes included in the STATES list provided in the starter code), the average median income for a state should be displayed formatted as

' Average median income in {:2s}: ${:

counties and their income; display them. You need first to display two header

lines:

' Top 10 Counties by Median Household Income (2018)' '{:

The format for all the numbers is as follow:

'{:

c) If option is '3', Call bottom_counties_by_income a function to

determine the bottom 10 counties and their income; display them. You need first

to display two header lines:

' Bottom 10 Counties by Median Household Income (2018)' '{:

The format for all the numbers is as follow:

'{:

d) If option is '4', Call top_states_by_income to determine the top 10

states by income; display them. You need first to display two header lines:

' Top 10 States by Average Median Household Income (2018)' '{:

The format for all the numbers is as follow:

'{:

e) If option is '5', Call bottom_states_by_income to determine the

bottom 10 by income; display them. You need first to display two header lines:

' Bottom 10 States by Average Median Household Income (2018)' '{:

The format for all the numbers is as follow:

'{:

f) If option is '6', Display all the counties and income for a state. Your code should prompt the user to input a 2-letter code. If it is valid (if it is one of the codes included in the STATES list provided in the starter code), you should first display the number of counties in a state in alphabetical order. If there are no counties in a state, use the following formatting:

 ' There are 0 counties in {}' 

If there are at least 1 county in the state, use the following formatting:

 ' There are {} counties in {}:' 

then print the average median income for each county in the state (if they exist). You need to print a header line:

'{:

All the numbers should be formatted as:

'{:

g) Display an error message if it is an invalid option.

5. Display the options again and prompt for input.

image text in transcribedimage text in transcribed

Strings we're required to use:

'Input a file: ' 'Invalid filename, please try again.' " Median Income Data" 'Choose an option, q to quit: ' 'Please enter a 2-letter state code: ' 'Please input a valid state' ' Average median income in {:2s}: ${: 

small version of csv:

FIPStxt,area_name,Civilian_labor_force_2018,Employed_2018,Unemployed_2018,Unemployment_rate_2018, Civilian_labor_force_2019 , Employed_2019 , Unemployed_2019 ,Unemployment_rate_2019,Median_Household_Income_2018,Med_HH_Income_Percent_of_State_Total_2018 01001,"Autauga County, AL","26,196","25,261",935,3.6,"26,172","25,458",714,2.7,"59,338",119.0 01003,"Baldwin County, AL","95,233","91,809","3,424",3.6,"97,328","94,675","2,653",2.7,"57,588",115.5 06001,"Alameda County, CA","842,427","816,611","25,816",3.1,"844,346","819,675","24,671",2.9,"101,744",135.2 06003,"Alpine County, CA",547,522,25,4.6,551,523,28,5.1,"55,384",73.6 06005,"Amador County, CA","14,686","14,084",602,4.1,"14,900","14,328",572,3.8,"58,515",77.8 06007,"Butte County, CA","101,932","96,749","5,183",5.1,"99,242","94,162","5,080",5.1,"50,945",67.7 06009,"Calaveras County, CA","21,188","20,329",859,4.1,"21,428","20,616",812,3.8,"62,984",83.7 72147,"Vieques Municipio, PR","2,718","2,269",449,16.5,"2,585","2,406",179,6.9,, 72149,"Villalba Municipio, PR","7,311","6,154","1,157",15.8,"7,406","6,231","1,175",15.9,, 72151,"Yabucoa Municipio, PR","8,762","7,509","1,253",14.3,"8,691","7,552","1,139",13.1,, 72153,"Yauco Municipio, PR","9,716","8,288","1,428",14.7,"9,759","8,331","1,428",14.6,,

I just need help with the main function of this project.

Here is the format for the other functions but I just need help with the main one:

import csv from operator import itemgetter STATES = ["AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV", "NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA", "RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV", "WI", "WY"] def open_file(): """Insert Docstring here""" pass def get_county_state(s): """Insert Docstring here""" pass def read_file(fp): """Insert Docstring here""" pass def state_average_income(state, master_list): """Insert Docstring here""" pass def top_counties_by_income(master_list): """Insert Docstring here""" pass def bottom_counties_by_income(master_list): """Insert Docstring here""" pass def top_states_by_income(master_list): """Insert Docstring here""" pass def bottom_states_by_income(master_list): """Insert Docstring here""" pass def counties_in_state(state, master_list): """Insert Docstring here""" pass def display_options(): """ DO NOT CHANGE Display menu of options for program """ OPTIONS = """ Menu 1: Average median household income in a state 2: Highest median household income counties 3: Lowest median household income counties 4: Highest average median household income states 5: Lowest average median household income states 6: List counties' median household income in a state """ print(OPTIONS) def main(): print(" Median Income Data") pass if __name__ == '__main__': main()
j. def main() Your main algorithm will be as follows calling the above functions. 1. Call open_file to open an input file for reading 2. Call read_file to read the desired data into a "master list of tuples. 3. Display a menu of options and prompt for input (use the display_options function to display the menu). 4. Loop until the input is"q" Based on the input: a) If option is '1', Call state_average_income to determine the average median income for a state; display it. Your code should prompt the user to input a 2-letter code. If it is valid (if it is one of the codes included in the STATES list provided in the starter code), the average median income for a state should be displayed formatted as Average median income in (:2s): ${:

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

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions