Create a program stat.py
that finds the mean, median, and mode in a list of numbers read in from a file numbers.txt
. Do not use the python statistics package. Some definitions:
Recommended Development Steps:
list(range(1,11))
and then append(1)
to your list so you will have a mode. Print out the numbers.1
to your list and print out the mean, median, and mode.numbers.txt
, which should have a number entered one per line.file_input(filename)
: returns the list of numbers read in from file filenamemean(numbers)
: takes a list of numbers as a parameter and returns their meanmedian(numbers)
: takes a list of numbers as a parameter and returns their medianmode(numbers)
: takes a list of numbers as a parameter and returns their modeHints:
There are two different ways to sort a list: sorted
and sort
. The function sorted(list)
returns a sorted version of the list without modifying the original, whereas list.sort()
doesn’t return anything but does change the original:
>>> list = [5, 7, 5, 1, 5]
>>> sorted(list)
[1, 5, 5, 5, 7]
>>> print(list)
[5, 7, 5, 1, 5]
>>> list.sort()
>>> print(list)
[1, 5, 5, 5, 7]
Make sure you don’t have any blank lines in your file.
When you’ve attempted the PHW, you can see my solution.