Store Statistics in Python

Overview

Due:
11:00pm, Friday September 18, 2020
Max grace days:
2

The purpose of this assignment is to write a basic Python program.

Description

A store needs a program to calculate the sales statistics for each department this year. The store has standard sales amount (in thousand dollars) for each month based on data from previous years.

The monthly sales amounts for departments are stored in a file sales.dat. Each line in the file contains twelve sales amounts for that department.

Month Standard
Jan 23.0
Feb 33.1
Mar 21.0
Apr 23.5
May 54.0
Jun 34.3
Jul 35.0
Aug 45.0
Sep 56.3
Oct 45.6
Nov 34.0
Dec 55.0

Write a program to calculate statistics for each department in the store. Your program should do the following:

  1. Prompt the user for the input file.
  2. Read the file data into a list of lists – a 2D list.
  3. Compute the average monthly sale for each department.
  4. Compare each monthly sales amount with the standard.
  5. Write the statistics for the department, including department number, average sales amount, numbers of months above and below the standard, and performance to a file. The program should output “unsatisfied” as the performance of the department if more than four months are below the standard and “satisfied” otherwise.

The output file must have the following format: the first line must be

Department,Average,Above,Below,Performance

and each subsequent line contains the appropriate values in the correct order separated by commas. The average value must be output with one decimal point of precision.

Your program must be composed of the following functions with the exact names, formal parameters and return values:

Note that you may create your own helper functions if you wish. The last line in the script should call the main function.

The use of any of the following Python features will result in a grade of zero for this assignment:

Sample input file

sales.dat

23 33.5 21 23 25 56 54 43 34.2 35.4 34 69.5
24 35.2 24 26 43 56.7 54 32 43 34 34 57.9
24 42 43 35 52 56 67 54 56 45.3 32 32
20 32 45 72 45.4 63.2 45 56 52 65 53 65
34 35 37.5 32 23 45 31 43 52 43 76 65
35 56 63.4 45.2 45.6 56 67.3 45 56.3 67 78 76
34.2 45 62 19 45 39 38 37 82 74 45 58.4

Sample output file

out.dat

Department,Average,Above,Below,Performance
1,37.6,7,5,unsatisfied
2,38.6,8,4,satisfied
3,44.9,7,5,unsatisfied
4,51.1,8,4,satisfied
5,43.0,7,5,unsatisfied
6,57.6,11,1,satisfied
7,48.2,9,3,satisfied

Turning in the Assignment

You must turn in a file named main.py. Submit the program source file to the appropriate folder on D2L.

Grading Criteria

Grading (out of 100 points):