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

Write a function, sortedSales(ifile) which takes the OfficeSupplies.csv file and

ID: 3726035 • Letter: W

Question

Write a function, sortedSales(ifile) which takes the OfficeSupplies.csv file and uses a dictionar... Write a function, sortedSales(ifile) which takes the OfficeSupplies.csv file and uses a dictionary to calculate and store the total sales of each sales person. This function prints the salesperson and their associated sales in order of highest value of sales to lowest value of sales with the salesperson’s name. In Python

This is the output

>>>sortSalesC'OfficeSupplies.csv) Alex Rachel : $3,191.67 Bill Richard: $1,721.15 James Nick Morgan : $1,156.01 Matthew$985.85 Smith Rich Thomas Susan : $4,206.38 : $2,476.90 : $1,411.56 : $1,157.49 : 730.76 :319.76 307.37 : 262.98

Explanation / Answer

#if there is any problem, please tell in comments def sortSales(file): d={} firstLine=True with open(file,'r') as f: for lines in f: if firstLine: firstLine=False else: item=lines.split(',') sale=int(item[4])*float(item[5]) name=item[2] if name in d: d[name]+=sale else: d[name]=sale sales=[] for i in d: sales.append(d[i]) sales.sort(reverse=True) for i in range(0,len(sales)): for j in d: if d[j]==sales[i]: print('{:10s}: ${:.2f}'.format(j,d[j])) sortSales('OfficeSupplies.csv')

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote