"P_record.csv" contains the records of patients in a hospital. Each record of the file contains the following data:["Gunjan", "Jaundice", 4, 15000]read_data() which reads all the data from the file and displays the details of all the 'Cancer' patients.count_rec() which counts and returns the number of records in the file.
def read_data():
try:
import csv
with open("P_record.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
if row[1].lower() == "cancer":
print(row)
except FileNotFoundError:
print("File not found.")
Explanation:
def count_rec():
count = 0
try:
import csv
with open("P_record.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
count += 1
return count
except FileNotFoundError:
print("File not found.")
return 0
Explanation: