Answered step by step
Verified Expert Solution
Question
1 Approved Answer
accounts.txt: Bob:234.70 Johnson:791.56 Anna:3260.55 Jill:-23.76 Smith:Not_A_Float! James:1022.71 Sarah:-567.30 George:eleven Vanessa:43781.43 Zoya:417.99 The goall of this lab is to practice writing code using Exceptions, Bounded Queues,
accounts.txt:
Bob:234.70 Johnson:791.56 Anna:3260.55 Jill:-23.76 Smith:Not_A_Float! James:1022.71 Sarah:-567.30 George:eleven Vanessa:43781.43 Zoya:417.99
The goall of this lab is to practice writing code using Exceptions, Bounded Queues, Circular Queues and Single Linked List 1 In this hree functions: def main() def readAccounts(infile) def processAc counts(accounts) program you must wite three functions. Here is the definition of the n the main function the user is asked to enter the name of the fie.f the fle 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 flename entered by the user does not exxist: Enter filename >doesnotexit.txt IOError.Input file does not exist If the fle exists, the main function opens the fle in read mode and proceeds to call a function readAccounts. The main function passes the T object (the file handler) as an argument to this function. extlOWrapper 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 anexception 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 al 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 a dictionary that was returned by readAccount s 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 thedictionary a KeyValue Error is raised and caught by the and pass the The following message is displayed in this case: The goall of this lab is to practice writing code using Exceptions, Bounded Queues, Circular Queues and Single Linked List 1 In this hree functions: def main() def readAccounts(infile) def processAc counts(accounts) program you must wite three functions. Here is the definition of the n the main function the user is asked to enter the name of the fie.f the fle 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 flename entered by the user does not exxist: Enter filename >doesnotexit.txt IOError.Input file does not exist If the fle exists, the main function opens the fle in read mode and proceeds to call a function readAccounts. The main function passes the T object (the file handler) as an argument to this function. extlOWrapper 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 anexception 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 al 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 a dictionary that was returned by readAccount s 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 thedictionary a KeyValue Error is raised and caught by the and pass the 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