Answered step by step
Verified Expert Solution
Question
1 Approved Answer
where am i going wrong on this: # Open and read health data file one line at a time # Columns are # disease,increase,location,number,population,year import
where am i going wrong on this: # Open and read health data file one line at a time
# Columns are
# disease,increase,location,number,population,year
import csv
file openhealthnoheadsample.csvr
# Process each line of the file
for aline in file:
print aline
values aline.split
print values
def loaddatahealthnohead:
with openhealthnohead, newline as file:
reader csvDictReaderfile
return listreader
def formatnumbernumber:
return :formatnumber
def displaytabledata:
header State "Disease", "Number", "Year"
print::::formatheader
for row in data:
print::::formatrowState rowDisease formatnumberintrowNumber rowYear
def filterdatadata stateNone, diseaseNone, yearNone:
filtereddata data
if state:
filtereddata row for row in filtereddata if rowStatelower state.lower
if disease:
filtereddata row for row in filtereddata if rowDiseaselower disease.lower
if year:
filtereddata row for row in filtereddata if rowYear year
return filtereddata
def getinputprompt:
userinput inputprompt
if userinput.strip:
return None
return userinput.strip
def main:
data loaddatahealthnohead.csv
state getinputEnter state Empty means all:
disease getinputEnter disease Empty means all:
year getinputEnter year Empty means all:
filtereddata filterdatadata state, disease, year
displaytablefiltereddata
if filtereddata:
totalcases sumintrowNumber for row in filtereddata
highestcases maxfiltereddata, keylambda x: intxNumber
lowestcases minfiltereddata, keylambda x: intxNumber
print
Total cases:", formatnumbertotalcases
printHighest number of cases:", highestcasesNumberin highestcasesState highestcasesDisease highestcasesYear
printLowest number of cases:", lowestcasesNumberin lowestcasesState lowestcasesDisease lowestcasesYear
if namemain:
main
# Close file
file.close
MEASLES COLORADO
MEASLES CONNECTICUT
MEASLES DELAWARE
MEASLES DISTRICT OF COLUMBIA
MEASLES FLORIDA
POLIO COLORADO
POLIO CONNECTICUT
POLIO DELAWARE
POLIO DISTRICT OF COLUMBIA
POLIO FLORIDA
SMALLPOX COLORADO
SMALLPOX CONNECTICUT
SMALLPOX DELAWARE
SMALLPOX DISTRICT OF COLUMBIA
SMALLPOX FLORIDA
MEASLES COLORADO
MEASLES CONNECTICUT
MEASLES DELAWARE
MEASLES DISTRICT OF COLUMBIA
MEASLES FLORIDA
POLIO COLORADO
POLIO CONNECTICUT
POLIO DELAWARE
POLIO DISTRICT OF COLUMBIA
POLIO FLORIDA
SMALLPOX COLORADO
SMALLPOX CONNECTICUT
SMALLPOX DELAWARE
SMALLPOX DISTRICT OF COLUMBIA
SMALLPOX FLORIDA
MEASLES COLORADO
MEASLES CONNECTICUT
MEASLES DELAWARE
MEASLES DISTRICT OF COLUMBIA
MEASLES FLORIDA
POLIO COLORADO
POLIO CONNECTICUT
POLIO DELAWARE
POLIO DISTRICT OF COLUMBIA
POLIO FLORIDA
SMALLPOX COLORADO
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started