The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 4 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
*python 3.1 ( Please provide me both the function and the main program and also the output to make sure the program does work)
Â
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