Answered step by step
Verified Expert Solution
Question
1 Approved Answer
MUST BE IN PYTHON 3 Q1 In this program you must write three functions. Here is the definition of the three functions def main() def
MUST BE IN PYTHON 3
Q1 In this program you must write three functions. Here is the definition of the three functions def main() def readAccounts(infile) def processAccounts (accounts) in the main function the user is asked to enter the name of the file. If the file does not exist, the main function should raise an exception. If raised, the main function should be able to catch the IOError exception. Upon catching the exception, the main function prints an error message and exits the program. Here is a sample run that shows what happens when the filename entered by the user does not exist: Enter filename >doesnotexit.txt IOError. Input file does not exist If the file exists, the main function opens the file in read mode and proceeds to call a function readAccounts. The main function passes the TextlOWrapper object (the file handler) as an argument to this function. Each line in the file is a record of a person's name followed by a colon symbol followed by a number that represents the amount the person has in their account The function readAccount reads the file one line at a time and stores the name:account as a key:value pair inside the dictionary. If the amount value associated to a name is not a valid number the function should raise an exception and that name: amount with the invalid amount is not added to the dictionary. If an exception is raised, the following message is printed by the function ValueError. Account for Smith not added: illegal value for balance After raising and catching the exception the program should continue to the next record in the file. Once all records with valid amounts have been added into the dictionary, the readAccounts function should return this dictionary The main function should now call the processAccounts function and pass the dictionary that was returned by readAccounts as an argument to this function This function should ask the user to enter the name of a person. If the name does not exist in the dictionary a KeyValue Error is raised and caught by the program. The following message is displayed in this caseStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started