Programming Exercise 11

  < Previous  Next >

Due Date

See the calendar for due date.

Assignment:

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 file

Example

The following is an example of correct execution (with the text in bold being the input from the user):
Enter the name of the file: numbers.txt
Opened numbers.txt for reading
Average: 50
Min: 25
Max: 75
Calculations based on 3 numbers

Submission

Submit your python script using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  pe11  pe11.py
To verify your submission, type the following in a terminal window:
handin  pe11