Write a function called max_age(inFile, outFile, breed), that takes three strings as input parameters. The function reads all the data from the inFile (1st input parameter) and writes data to the outFile (2nd input parameter) as described below.
Write a function called max_age(inFile, outFile, breed), that takes three strings as input parameters. The function reads all the data from the inFile (1st input parameter) and writes data to the outFile (2nd input parameter) as described below.
Each line in the input file represents a pet record and has the following format.
name, breed, age
where name and breed are strings, and age is an integer value.
Your function must find the oldest pet of a given breed (3rd input parameter) from the inFile and write the following information to the outFile.
breed, total records of this breed
name of the oldest pet, age of the oldest pet
Note that outFile must only have these two lines of information.
Suppose, inFile contains the following data:
shadow, longhair, 3
poshi, bangal, 5
mikus, longhair, 4
tigger, calico, 9
If you call this function with breed = "longhair", then the following must be written in the outFile:
longhair, 2
mikus, 4
Your function must return True if both reading and writing were successful, and False otherwise. This function should properly handle all exceptions so that your program does NOT crash.
You do not have to write a main() function for this program.
Save this program as q3_studentNumber.py where studentNumber should be replaced by your Carleton student number. Upload this py file using the submission link available at the end of this question. You do not need to zip the file
Step by step
Solved in 4 steps with 2 images