Question: Write a program that will search a text file of strings representing numbers of type int and will write the following to the screen: a

Write a program that will search a text file of strings representing numbers of type int and will write the following to the screen:

  • a count of integers in the file
  • largest integer in the file
  • smallest integer in the file
  • average of the integers in the file
  • sum of all integers in the file

Include appropriate error handling in case a line contains more than one int or it contains a String. Wrap all the work you are doing with the file in a try/catch/finally block with appropriate "catch" sections; the finally block will be where you close your file object (if desired, look this up online for more information regarding "finally" and when it is executed, specifically that it is executed in case of success or failure of the entire try block).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Python program that reads a text file containing integers performs calculations and handles potentia... View full answer

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 Programming Questions!