Answered step by step
Verified Expert Solution
Link Copied!

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,

image text in transcribed

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 image text in transcribed

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 case

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced MySQL 8 Discover The Full Potential Of MySQL And Ensure High Performance Of Your Database

Authors: Eric Vanier ,Birju Shah ,Tejaswi Malepati

1st Edition

1788834445, 978-1788834445

More Books

Students also viewed these Databases questions

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

6. Discuss the steps involved in conducting a task analysis.

Answered: 1 week ago

Question

8. Explain competency models and the process used to develop them.

Answered: 1 week ago