Created
March 29, 2019 01:05
-
-
Save prajwal-stha/c23a23f35951b0525c1129a29180ebc5 to your computer and use it in GitHub Desktop.
Answer for Practice Question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_max_min_sales(min_max_sold_index): | |
foodItemIndex = ['Burger', 'Pizza', 'Coke','Fries', 'Cake'] | |
try: | |
index = foodItemIndex[min_max_sold_index] | |
except IndexError: | |
pass | |
return index | |
file = open("sales_data-sales_data.csv", "r") | |
data = file.readlines() | |
file.close() | |
sales_list = [] | |
total_days = 14 | |
avg_pizza = 0 | |
avg_burger_friday = 0 | |
avg_pizza_friday = 0 | |
avg_coke_friday = 0 | |
avg_fries_friday = 0 | |
avg_cake_friday = 0 | |
total_cake = 0 | |
total_fries = 0 | |
total_burger_fries = 0 | |
for d in data: | |
sales_list.append(d.replace("\n","").split(",")) | |
for i in range(1, len(sales_list)): | |
for j in range(1, len(sales_list[i])): | |
# The column data is for pizza sales | |
if j == 2: | |
avg_pizza += int(sales_list[i][j]) | |
# Total number of Cakes | |
if j == 5: | |
total_cake += int(sales_list[i][j]) | |
# Total number of Fries | |
if j == 4: | |
total_fries += int(sales_list[i][j]) | |
# Least Sold Item and Highest sold item on average on fridays | |
if sales_list[i][0] == 'Friday': | |
if j == 1: | |
# Avg Burger | |
avg_burger_friday += int(sales_list[i][j]) | |
if j == 2: | |
# Avg Pizza | |
avg_pizza_friday += int(sales_list[i][j]) | |
if j == 3: | |
# Avg Coke | |
avg_coke_friday += int(sales_list[i][j]) | |
if j == 4: | |
# Avg Fries | |
avg_fries_friday += int(sales_list[i][j]) | |
if j == 5: | |
# Avg Cake | |
avg_cake_friday += int(sales_list[i][j]) | |
# Total number of Burger and Fries | |
if sales_list[i][0] in ['Saturday', 'Sunday'] and (j == 1 or j == 4): | |
total_burger_fries += int(sales_list[i][j]) | |
avg_sales_list = [avg_burger_friday/2, avg_pizza_friday/2, avg_coke_friday/2, avg_fries_friday/2, avg_cake_friday/2] | |
max_sold_index = avg_sales_list.index(max(avg_sales_list)) | |
min_sold_index = avg_sales_list.index(min(avg_sales_list)) | |
# Find Max and Min Sold Item | |
min_sold_item = find_max_min_sales(min_sold_index) | |
max_sold_item = find_max_min_sales(max_sold_index) | |
print(f'The average numbers of pizza sold are {int(avg_pizza / total_days)}') | |
print(f'The least sold item and the highest sold item on average on fridays are {min_sold_item} and {max_sold_item}') | |
print(f'The total numbers of Cakes sold are {total_cake}') | |
print(f'The total numbers of Fries sold are {total_fries}') | |
print(f'The combined total of burgers and fries sold so far on saturays and sundays are {total_burger_fries}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment