(60 Points)
Speed Reading: Average all of the numbers from an input file
(perhaps with multiple numbers on some input lines).
This problem requires you to combine the ideas of:
-
defining functions,
-
reading from files,
-
while loops, and
-
using a graphics window to get user input.
Your task is to read numbers from a file and calculate the mean of the numbers. Unfortunately, the file is a bit malformed. The numbers are generated by a radar gun that measures the speed of each vehicle on the road coming up the hill from the SRC. Due to an intermittent open circuit occasionally multiple numbers are written on a single line, like this:
23.2 15.6 19.8
A sample input file, speeds.txt, is in your project.
Open the speedReading.py file in the
Session10 project that you checked out from SVN in class.
Modify it to calculate the arithmetic mean (average) of the numbers in a file. Your
program must conform to the following specification:
-
Your program should ask the user for the name of the input file to process. Rather than using “console” input, your program should use a GUI similar to the one in Figures 5.9 and 5.10 on pages 150 and 151 of Zelle’s text book. Use an Entry object (Zelle, page 148) to accept the input file name from the user.
-
Your program should display the final average in the GUI window.
Hint: You can use the
setText()
method to change the displayed value of a string that has already been drawn.
- Your program should use the four functions as given in
speedReading.py:
- line_sum_and_count()
- mean_fo_filer()
- get_input_file()
- main()
- Yes, there are many other ways
that you could write this. We're asking you to follow our specification so you can get practice working with the sort of situations that come up in real world, group projects, where you
often must implement someone else's design design.
We also think that doing it this way will get you to
confront some issues and clear up some misunderstandings
that you may have about functions.
- Test your program using the test functions we provided in main(). Test as you go: write and test line_sun_and_count first,
then write and test mean_for_file, and finish up by creating the GUI
and testing it on the file speeds.txt in your project. The
average of the speeds in that file should be around 20.16.
- Commit your file to your SVN repository.