*python 3.1
Write and test the following function:
def median_scores(fv):
"""
-------------------------------------------------------
Determines the median of a series of integers in a file.
Use: m = median_scores(fv)
-------------------------------------------------------
Preconditions:
f - a file variable for a file of integers (file)
Postconditions:
returns
median - the median of the values in the file (float)
-------------------------------------------------------
"""
Here a median is the middle element of a sorted list if the number of elements is odd, and the average of the two middle elements if the number of elements is even. You may use Python's built-in sort method to sort the contents of the list after they have been read from the file.
Use the file numbers.txt. for testing.
numbers.txt
12
15
32
14
3
234
197
45
241
67
18
91
126
22
111
4
78
21
200
183
9
37
42