Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

def get_data(file_name): ---data_list=[] ---with open(file_name,'r') as read_file: ------for line in read_file.readlines(): ---------line=line.strip().split(',') ---------record=[] ---------record.append(line[2]) # state ---------record.append(line[0]) # disease ---------record.append(line[3]) # number ---------record.append(line[-1]) # year

def get_data(file_name):

---data_list=[]

---with open(file_name,'r') as read_file:

------for line in read_file.readlines():

---------line=line.strip().split(',')

---------record=[]

---------record.append(line[2]) # state

---------record.append(line[0]) # disease

---------record.append(line[3]) # number

---------record.append(line[-1]) # year

---------data_list.append(record)

---return data_list

def print_data(records):

---print('{0:<25}{1:<10}{2:>10}{3:>7}'.format('State','Disease','Number','Year'))

---for record in records:

-----print('{0:<25}{1:<10}'.format(record[0],record[1]),end='')

-----print(format(int(record[2]),'10,d'),end='')

-----print('{0:>7}'.format(record[3]))

def find(records):

---state=input('Enter state: ').upper()

---disease=input('Enter disease: ').upper()

---year=input('Enter year: ')

---if state == '' and disease == '' and year == '':

-----return records

---elif state == '' and disease is not '' and year is not '':

-----return [record for record in records if disease==record[1] and year==record[3]]

---elif state is not '' and disease is not '' and year == '':

-----return [record for record in records if state==record[0] and disease==record[1]]

---elif state is not '' and disease == '' and year is not '':

-----return [record for record in records if state==record[0] and year==record[3]]

---elif state is not '' and disease == '' and year == '':

-----return [record for record in records if state == record[0] ]

---elif state == '' and disease is not '' and year == '':

-----return [record for record in records if disease == record[1] ]

---elif state == '' and disease == '' and year is not '':

-----return [record for record in records if year == record[3] ]

---else: return [record for record in records if state == record[0] and disease==record[1] and year == record[3]]

def main():

---records=get_data('F:\\health-no-head-sample.csv')

---print_data(records) matched_records=find(records)

---print_data(matched_records)

main()

_______________________________________________________________-

Modify the program in the following ways:

  1. add to the program so it give total number of disease after the quary is complete like below State Disease Number Year COLORADO MEASLES 2,099 1928 CONNECTICUT MEASLES 10,014 1928 DELAWARE MEASLES 597 1928  DELAWARE SMALLPOX 0 1930 DISTRICT OF COLUMBIA SMALLPOX 0 1930 FLORIDA SMALLPOX 28 1930  Total 52,307 
  2. Add another feature to your program that print the highest and lowest numbers for each query

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_2

Step: 3

blur-text-image_3

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

Modern Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions

Question

1-4 How will MIS help my career?

Answered: 1 week ago