CBSE · 083Class XII · 2025Section D2 marks
Question 33i
4 March 2025 · Computer Science (083)
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 Write the following Python functions to perform the specified operations on this file:
(i) Write a function read_data() which reads all the data from the file and displays the details of all the 'Cancer' patients.
Answer
python
import csv
def read_data():
F=open("P_record.csv","r")
Records=list(csv.reader(F))
for R in Records :
if R[1]=="Cancer":
print(R)
F.close()Explanation
Uses csv module to read rows and checks index 1 for disease name.