Advertisements
Advertisements
प्रश्न
A csv file "P_record.csv" contains the records of patients in a hospital. Each record of the file contains the following data:
- Name of a patient
- Disease
- Number of days patient is admitted
- Amount:
For example, a sample record of the file may be: ["Gunjan","Jaundice",4,15000]
Write the following Python functions to perform the specified operations on this file:
- Write a function
read_data()which reads all the data from the file and displays the details of all the'Cancer'patients. - Write a function
count_rec()which counts and returns the number of records in the file.
कोड लेखन
Advertisements
उत्तर
import csv
def read_data():
f = open("P_record.csv","r")
cr = csv.reader(f)
for rec in cr :
if rec[1]="Cancer":
print(rec)
def count_rec():
count = 0
f = open("P_record.csv","r")
cr = csv.reader(f)
for rec in cr:
count+ = 1
print("No.of records:",count)
return countshaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
