मराठी

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 - Computer Science (Python)

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:

  1. Write a function read_data() which reads all the data from the file and displays the details of all the 'Cancer' patients.
  2. 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 count
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
2024-2025 (March) Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×