# Q1: What is Fahad's revenue?
# Good solution: write a function that takes a seller as argument
# and returns the revenue for this seller

def sellerRevenue(record, months, sellers, name):
    # get the index of the seller
    index = sellers.index(name)
    res = 0
    for i in range(len(record[index])):
        res = res + record[index][i]
    return res

# Q2: Who is the best seller?
# Good solution: write a function that does not take any argument
# and returns the name of the best seller

def bestSeller(record, months, sellers):
    best = sellers[0]
    score = sellerRevenue(record, months, sellers, best)
    for seller in sellers:
        r = sellerRevenue(record, months, sellers, seller)
        if r >score:
            best = seller
            score = r
    return best

# Q3: What was the revenue in February?
# Good solution: write a function that takes a month as argument
# and returns the revenue for this month

def monthRevenue(record, months, sellers, month):
    # get the index of the month
    index = months.index(month)
    res = 0
    for i in range(len(sellers)):
        res = res + record[i][index]
    return res

# Q4: when was the best month?
# Good solution: write a function that does not take any argument
# and returns the name of the best month

def bestMonth(record, months, sellers):
    best = months[0]
    score = monthRevenue(record, months, sellers, best)
    for month in months:
        r = monthRevenue(record, months, sellers, month)
        if r > score:
            best = month
            score = r
    return best

# Q5: what is the total revenue?
# two similar solutions here:
# solution 1: iterate through the sellers and add their revenue
# solution 2: iterate through the months and add their revenue

def total(record, months, sellers):
    res = 0
    for seller in sellers:
        res = res + sellerRevenue(record, months, sellers, seller)
    return res

##### Data #####

record = [[0,0,0,0,0,0],[ 456 , 235 , 987 , 673 , 776 , 427], [ 856 , 284 , 413 , 987 , 629 , 196,0 ], [ 198 , 936 , 648 , 925 , 435 , 662,0 ], [174 , 816 , 367 , 357 , 856 , 1045 ]]

months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
sellers = ["tsans","Fahad", "Emad", "Mariam", "Sarah"]

test = sellerRevenue(record, months, sellers, "Fahad")
print "Fahad's revenue: " + str(test)

test = bestSeller(record, months, sellers)
print "The best seller is " + test

test = monthRevenue(record, months, sellers, "Feb")
print "Total revenue in February: " + str(test)

test = bestMonth(record, months, sellers)
print "The best month was " + test

test = total(record, months, sellers)
print "The best month was " + str(test)
