Practice PHW14: Final Exam Review

stat.py

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:

  1. Instead of reading in from a file, create a list of numbers with list(range(1,11)) and then append(1) to your list so you will have a mode. Print out the numbers.
  2. Print out the mean for the list of numbers.
  3. Print out the median for the list of numbers.
  4. Print out the mode for the list of numbers.
  5. Append another 1 to your list and print out the mean, median, and mode.
  6. Read in a file numbers.txt, which should have a number entered one per line.
  7. Write functions to read in the data from a file & calculate each statistic:
    • file_input(filename): returns the list of numbers read in from file filename
    • mean(numbers): takes a list of numbers as a parameter and returns their mean
    • median(numbers): takes a list of numbers as a parameter and returns their median
    • mode(numbers): takes a list of numbers as a parameter and returns their mode

Hints:

Solution

When you’ve attempted the PHW, you can see my solution.