I'm trying to create a program in python and need assistance in creating it. Here's what I'm trying to create: Program that reads a series of integers from a file named numbers.txt (image of file...


I'm trying to create a program in python and need assistance in creating it. Here's what I'm trying to create:





  • Program that reads a series of integers from a file named

    numbers.txt

    (image of file attached), calculates the average of the integers and displays the average to the console.




  • Wrap the code in a
    try block that has three associated exception blocks. The three exception blocks must handle the following exception types:IOError, ValueError and a catch-all exception. If anIOError exception is caught, display the following message to the console (screen) "An error occurred while trying to read the file.". If anValueError exception is caught, display the following message to the console (screen) "Non-numeric data found in the file.". Ifany other exception
    is caught, display the following message to the console (screen) "An error occurred."




  • The programmust read until End-Of-File (EOF) meaning that the programmust be able to read an indeterminate number of records
    from the file.




Attached images include pseudo code and numbers.txt file contents.


Method main:<br>Declare any necessary local variables.<br>Inside a try-block is the following code:<br>Open the numbers.txt file in 'read' mode.<br>For every line in the file do the following:<br>Convert the line from the file to an integer.<br>Keep a running count of the number of integers from the file.<br>Keep a running total of the integers from the file.<br>Close the file.<br>Calculate the average.<br>Print the average.<br>Code the three exception handler blocks per the instructions.<br>Call the main method.<br>

Extracted text: Method main: Declare any necessary local variables. Inside a try-block is the following code: Open the numbers.txt file in 'read' mode. For every line in the file do the following: Convert the line from the file to an integer. Keep a running count of the number of integers from the file. Keep a running total of the integers from the file. Close the file. Calculate the average. Print the average. Code the three exception handler blocks per the instructions. Call the main method.
22<br>14<br>-99<br>

Extracted text: 22 14 -99
Jun 08, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here