Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am currently trying to familiarize myself with python Here is what I am suppose to output: Store Statistics Dept Average Above Below Performance ---------------------------------------------------------------------------------------------
I am currently trying to familiarize myself with python
Here is what I am suppose to output:
Store Statistics Dept 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
I AM NOT ALLOWED TO USE: import statements, list comprehensions, generators, and higher-order functions
I am pretty sure my get_data is correct
Here is the rest of the requirements:
- process_data: takes a list of lists of floats, the list of standard sales, and returns a list of dictionaries. Each dictionary must have the following key names and values where the values correspond to the respective inner list:
- Department: (int) the department number (the inner list number where the first inner list is 1)
- Average: (float) the average of the list
- Above: (int) the number of entries greater than or equal to the standard.
- Below: (int) the number of entries less than the standard
- Performance: (string) The departments performance based number of months above or below the standard. Only two values should be unsatisfied or satisfied.
- write_to_file: takes a list of dictionaries of the form returned from process_data function and writes the values to a file. The file format is described above. This function must use at least one Python format string as part of the implementation. The output file must be out.dat
Example sales.dat File:
23.0 33.1 21.0 23.5 54.0 34.3 35.0 45.0 56.3 45.6 34.0 55.0 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
Here is my code so far, please DO NOT try changing my code please just help me try to fix it or add certain things. Thanks, anything helps
1 2 3 4 5 6 def get_data(filename) : filehandle = open(filename) outerlist = [] for line in filehandle: line = line.strip().split() for i in range(len(line)): line[i] = float(line[i]) outerlist.append(line) standard_sales = outerlist[0] department_sales = outerlist[1:8] return standard_sales, department_sales filehandle.close() 7 8 9 def process_data(*args, lis): list_of_dictionaries = [] dictionary = {} for i in range(1, len(lis)): average = sum(department_sales[i])/len (department_sales[i]). dictionary["Department"] = i dictionary["Average"] = average 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 def main(): filename = input("Enter File Name: ") get_data(filename) standard_data = get_data(filename) process_data(standard_data) main()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started