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 an IOError exception is caught, display the following message to the console (screen) "An error occurred while trying to read the file.". If an ValueError exception is caught, display the following message to the console (screen) "Non-numeric data found in the file.". If any other exception is caught, display the following message to the console (screen) "An error occurred." The program must read until End-Of-File (EOF) meaning that the program must be able to read an indeterminate number of records from the file. Attached images include pseudo code and numbers.txt file contents.

Enhanced Discovering Computers 2017 (Shelly Cashman Series) (MindTap Course List)
1st Edition
ISBN:9781305657458
Author:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Chapter10: Communicating Digital Content: Wired And Wireless Networks And Devices
Section: Chapter Questions
Problem 24CT
icon
Related questions
Question

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 an IOError exception is caught, display the following message to the console (screen) "An error occurred while trying to read the file.". If an ValueError exception is caught, display the following message to the console (screen) "Non-numeric data found in the file.". If any other exception is caught, display the following message to the console (screen) "An error occurred."

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

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

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.
Transcribed Image 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
14
-99
Transcribed Image Text:22 14 -99
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Exception Handling Keywords
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Enhanced Discovering Computers 2017 (Shelly Cashm…
Enhanced Discovering Computers 2017 (Shelly Cashm…
Computer Science
ISBN:
9781305657458
Author:
Misty E. Vermaat, Susan L. Sebok, Steven M. Freund, Mark Frydenberg, Jennifer T. Campbell
Publisher:
Cengage Learning