"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:
PASSENGERS.DAT stores the records of passengers using the following structure:Create() – to input data for passengers and write it in the binary file PASSENGERS.DAT.SearchDestn(D) – to read contents from the file PASSENGERS.DAT and display the details of those Passengers whose DESTN matches with the value of D.UpdateFare() – to increase the fare of all passengers by 5% and rewrite the updated records into the file PASSENGERS.DAT.