In: Computer Science
Solve using PYTHON 3 and use functions.
You have been hired by a restaurant named "Burger Shack" Per the client, you have the following information: the client’s name, burger’s name, time of the day, and the total bill. By the end of the day, your program will provide the following information:
1. Top three best clients (highest bills) 2. Name of the client with the second-to-last lowest bill 3. Busiest hour of the day (number of clients)
Assumptions: 1. doesn't handle more than 100 clients per day 2. this restaurant only has six types of burgers 3. restaurant hours are from 10:00am to 10:00pm
We can assume that at the end of the day the data will be in form of list of tuples where each tuple store client name, burger name,time of the day and total bill. We will take the time in 24 hour format. So the data will look like this.
sales_details = [("Alexa","Burger1","10.23",127),("Siri","Burger2","12.56",132),("Jarvis","Burger3","12.51",192)]
Have a look at the below code. I have put comments wherever required for better understanding.
def high_bills_and_low_bills(sales_details):
# Sort the sales details according to the price of burger in decreasing order
sales_details.sort(key = lambda x:[3],reverse = True)
# create an array to store client detilas with highest order
highest_bill_clients = []
# Loop in through the top three clients
for sales in sales_details[0:3]:
# Save their name in the array
highest_bill_clients.append(sales[0])
# Now we will reverse the array so that the entry with lower price comes first
sales_details = sales_details[::-1]
# get the clients with lowest order value
last_two_clients = [sales_details[-2][0],sales_details[-1][0]]
# return the list with client details
return highest_bill_clients, last_two_clients
# function to calculate busiest hour
def busiest_hour(sales_details):
# we will take a dictionary to keep trac of busiest hour
dct = {}
# loop in through sales details
for sales in sales_details:
# here we will slice the only the hour part of time because 11:23 and 11:45 will both lies in same hour that is 11-12.
hour = sales[2][0:2]
# here we will check if any order is already there in this hour, if yes then we increment the value
if hour in dct:
dct[hour]+=1
else:
# if not then we will set its value to one
dct[hour]=1
# here we will find the hour with maximum orders
peak_hour = None
cnt = -1
for key in dct:
if dct[key]>cnt:
peak_hour = key
cnt = dct[key]
x = peak_hour
y = str(int(peak_hour) + 1)
# here we will return the peak hour
return x + "-" + y
Happy Learning!