Programming Exercise 11 |
< Previous Next > |
Assume that a file containing a series of integers exists on your system. Write a program that calculates the average, minimum, and maximum of all the numbers stored in the file. The program should contain a main() function which prompts for the name of the file, attempts to open the file, verifies that the file opened correctly, and passes it to the function processNumbers(inFile) where inFile is a file object variable. The processNumbers() function should compute the average, minimum, and maximum values and print them to standard out. It should then return the total number of lines read to the main() function for error checking purposes. Be sure that the main() function closes the file after processing.
Sample input fileEnter the name of the file: numbers.txt Opened numbers.txt for reading Average: 50 Min: 25 Max: 75 Calculations based on 3 numbers
handin pe11 pe11.pyTo verify your submission, type the following in a terminal window:
handin pe11