Question: I am new to Python and this is difficult task for me. Can anybody help me? TASK 2: Write a python program that reads a

I am new to Python and this is difficult task for me. Can anybody help me?

I am new to Python and this is difficult task for me.

TASK 2: Write a python program that reads a series of integers (one integer on each line) from a file stored on hard disk and calculates the average of all the numbers in the file. The name of the file on the hard disk is numbers.txt The program handles the following separate individual exceptions: FileNotFoundError (OError) exceptions that are raised when file is opened and data is read from it. ValueError exceptions that are raised when items that are read from the file and converted to a number In case of any error, there should be a prompt asking if the user would like to correct the error and then execute. The user can correct the error and type 'Y' to continue execution or type any other letter to quit execution. In this task you will need to include three separate exception handlers-File NotFoundError (IOError), ValueError and another to capture any other error Hint: try: except FileNotFoundError: except ValueError: except: Sample Error output Case 1: If the fle numbers.txt did not exist (e.g. it was mistakenly named as 'nunbers.txt). The user corrected the file name and typed , to run again. The program then calculated and printed the average. FileNotFound error occurred while trying to read the file Type Y after correcting the error or type N to not continue: Y Average: 57.5 The user selected N to indicate quitting. FileNotFound error occurred while trying to read the file Type Y after correcting the error or type N to not continue: N you decided to quit. quiting.. Case 2: Assume that the numbers in the text file contains: 40, 80, 90o, 20 (each on separate line). 90o is not a valid data. Non-numeric data found in the file The last valid data read 80.0 The non-numeric data was on line 3 in the file Type Y if you want to correct and continue: Y Average: 57.5 Task 3: In Task2, you have three excepfon handlers - FileNotFoundError (IOError), ValueError and another to capture any other error. Modity the code to include only one exception handler, which will find the error type and will output the same output as in Task2. Hints except Exception as ex: print(" type is:", type(ex).-name print argsisexargs) ) # to get the name of type #toget the argument

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!