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

Suppose we have records on the daily sales of several sellers. We\'re interested

ID: 3724058 • Letter: S

Question

Suppose we have records on the daily sales of several sellers. We're interested in a subset of those sellers, and of the subset we're interested in, we want to identify those with the highest daily sales average. Let's look at an example:

Given a matrix of records:

and the subset of sellers "Alice Cathy", we can determine that Alice has the highest daily average of 4.5. Note that Bob has a higher overall daily average of 7, but we didn't specify him in our subset.

For this task we will make the following assumptions:

Each row in the matrix is exactly 2 elements long, with the first element being a string and the second element being a number

Matrices are always 2 dimensional and non-empty

The subset of sellers of interest must appear in the matrix

The output should be the name of the seller in the requested subset who has the highest daily sales average. However, if more than one seller is tied for the maximum, all names should be output, separated by spaces.

Input:

The rows of the matrix each on a separate line, followed by a blank line, and then seller names.

Output:

Print to standard output either the name(s) of the sellers in the subset with the highest daily sales average, or the string “NONE” if assumptions are not fulfilled.

python 3

Explanation / Answer

from array import *
import sys
l = []

i=0
j=0
k=0
for arg in sys.argv[1:]:
l.append(arg)

matrix = []
for i in range(0,int(len(l)/2)):
matrix.append([])
for j in range(0,2):
matrix[i].append(l[k])
k = k+1
  
print(matrix)

names = input("Enter subset of names separated by ,:")
names = names.split(",")
print(names)

# define sales matrix which will contain sales of subset
sales = []
for i in range(0,len(names)):
sales.append([])
for j in range(0,2):
sales[i].append(0)

k=0  

max_sales=0

for i in [0,len(names)]:
for j in [0,int(len(l)/2)]:
if matrix[j][0]==names[i]:
if names[i] not in sales:
sales[k][0]=names[i]
sales[k][1] = sales[k][0]+matrix[j][1]
  
k = k+1
else:
ind = sales.index(names[i])
sales[ind][1] = sales[ind][1]+matrix[j][1]
  
max_sales_sorted = sorted(li,key=lambda x: x[1])

print("Highest sales:")
print(max_sales_sorted[len(names)-1][0],max_sales_sorted[len(names)-1][1] )