DEV Community

Discussion on: Daily Challenge #187 - Most Sales

Collapse
 
amcmillan01 profile image
Andrei McMillan

python

def most_sales(product_list, amount_list, price_list):
    if len(product_list) == len(amount_list) == len(price_list):

        revenue_list = []
        top_revenue = []

        for i, n in enumerate(product_list):
            revenue_list.append(amount_list[i] * price_list[i])

        max_val = max(revenue_list)

        for index, value in enumerate(revenue_list):
            if value == max_val:
                top_revenue.append(str(product_list[index]) + ' - ' + '${:,.2f}'.format(value))

        print '\n'.join(top_revenue)
        print '\n' + ('-' * 20) + '\n'
    else:
        print('invalid entries')


most_sales(
    ["Computer", "Cell Phones", "Vacuum Cleaner"],
    [3, 24, 8],
    [199, 299, 399]
)
# Cell Phones - $7,176.00

most_sales(
    ["Cell Phones", "Vacuum Cleaner", "Computer", "Autos", "Gold", "Fishing Rods", "Lego", " Speakers"],
    [0, 12, 24, 17, 19, 23, 120, 8],
    [9, 24, 29, 31, 51, 8, 120, 14]
)
# Lego - $14,400.00

most_sales(
    ["Cell Phones", "Vacuum Cleaner", "Computer", "Autos", "Gold", "Fishing Rods", "Lego", " Speakers"],
    [120, 12, 24, 17, 19, 23, 120, 8],
    [120, 24, 29, 31, 51, 8, 120, 14]
)
# Cell Phones - $14,400.00
# Lego - $14,400.00