Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(Average Weekly sales and Average Sales Per Sales Person): Write two programs Cr

ID: 3814470 • Letter: #

Question

(Average Weekly sales and Average Sales Per Sales Person): Write two programs CreateSales. py and AverageSales. py. The first program (CreateSales. py) generates a sales file called sales.txt, which contains sales data for 12 weeks by 20 sales people. Sample data is given below. You may use random number function to generate floating point numbers between 0 and 200. Each row represents weekly sales by each sales person for 12 weeks. Data in each column represents sales for a particular week by 20 sales people. The second program (AverageSales. py) Computes average sales for each sales person and for each week. Sample Data wk1, wk2, wk3, wk4, wk5, wk6, wk7, wk8, wk9, wk10, wk11, wk12 55. 8, 131.2, 12. 5, 27.6, 105. 4, 181.7, 176. 3, 63.2, 179.4, 81.6, 126. 5, 122. 9, 167.2, 26.4, 141. 7, 137.8, 114 2, 180. 3, 66.8, 46.9, 154. 7, 56.8, 21.2, 148.6,

Explanation / Answer

Python 2.7 code:

from random import randint
import os.path
import sys
out_file = "Sales.txt"

table = []
for i in range(0,20):
   tmp = []
   for j in range(0,12):
       tmp.append(randint(0,200))
   table.append(tmp)

print "SalesPerson", " ", "TotalSales", " ", "AverageSales"
for i in range(0,20):
   s = 0
   for j in range(0,12):
       s = s + table[i][j]
   print i+1, " ", s , " ", s/(12.0)

print " "
print "Week", " ", "TotalSales", " ", "AverageSales"
for i in range(0,12):
   s = 0
   for j in range(0,20):
       s = s + table[j][i]
   print i+1, " ", s , " ", s/(20.0)

f= open(out_file,"w+")
for i in range(1,13):
   f.write("Wk")
   f.write(str(i))
   f.write(",")  
f.write(" ")

for i in range(0,20):
   for j in range(0,12):
       f.write(str(table[i][j]))
       f.write(",")
   f.write(" ")  

Sample Sales.txt:

Wk1,Wk2,Wk3,Wk4,Wk5,Wk6,Wk7,Wk8,Wk9,Wk10,Wk11,Wk12,
65,163,29,10,40,179,74,162,197,150,17,150,
48,34,87,156,32,13,31,39,111,48,173,107,
45,84,185,93,95,170,122,117,91,24,130,105,
85,174,118,164,60,94,40,45,165,114,103,56,
39,4,123,90,13,100,149,124,7,4,48,163,
104,74,36,63,164,121,107,102,111,37,164,107,
28,88,118,56,76,27,155,90,68,127,80,55,
144,103,164,112,183,16,157,67,55,108,183,110,
129,8,12,54,90,101,87,166,95,8,97,113,
16,158,137,86,90,39,95,4,47,28,200,68,
149,102,66,41,29,192,62,21,125,126,174,141,
27,6,83,58,31,27,102,76,64,48,25,177,
91,82,23,9,120,5,195,182,182,4,88,2,
115,68,180,93,75,197,174,79,132,179,136,36,
153,161,154,144,142,138,168,185,121,102,37,112,
12,187,7,139,49,13,95,153,140,11,154,102,
66,84,69,120,119,116,140,38,54,62,104,175,
3,190,46,67,161,198,55,127,3,172,97,29,
117,138,123,88,14,193,5,105,85,143,140,6,
187,3,52,182,119,23,96,162,17,128,43,28,

Sample Output:

SalesPerson TotalSales AverageSales
1 1236 103.0
2 879 73.25
3 1261 105.083333333
4 1218 101.5
5 864 72.0
6 1190 99.1666666667
7 968 80.6666666667
8 1402 116.833333333
9 960 80.0
10 968 80.6666666667
11 1228 102.333333333
12 724 60.3333333333
13 983 81.9166666667
14 1464 122.0
15 1617 134.75
16 1062 88.5
17 1147 95.5833333333
18 1148 95.6666666667
19 1157 96.4166666667
20 1040 86.6666666667

Week TotalSales AverageSales
1 1623 81.15
2 1911 95.55
3 1812 90.6
4 1825 91.25
5 1702 85.1
6 1962 98.1
7 2109 105.45
8 2044 102.2
9 1870 93.5
10 1623 81.15
11 2193 109.65
12 1842 92.1