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
W
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started