In: Computer Science
In PYTHON 3 using functions. Per the client, you have the following information: customer name, burger choice, time of purchase, and total bill. By the end of the day, your program will provide the following information:
1. Top three best clients with the highest spending
2. Name of client with second to last lowest bill
3. busiest hour of the day based on number of clients
Assumptions
1. Your program will not handle more than 100 clients per day
2. The restaurant only has six types of burgers
3. The restaurant works from 10:00 am until 10:00 pm
Python Code pasted below.
#Function definition
def top3Spenders(client_list):
#sort on total_bill to get the highest spender
client_list.sort()
#printing top three spenders
print("Top three best clients")
print("Name:",client_list[-1][1]," and highest spending:
",client_list[-1][0])
print("Name:",client_list[-2][1]," and highest spending:
",client_list[-2][0])
print("Name:",client_list[-3][1]," and highest spending:
",client_list[-3][0])
def secondLowestBill(client_list):
#printing name of the client with second to last lowest bill
print("Name of the client with second last lowest
bill:",client_list[1][1]," and the bill amount:
",client_list[1][0])
def busyHour(client_list):
#initializing an empty dictionary to store the time and its
count
dict={}
for item in client_list:
#Item is a tuple. In the tuple last one is the time. Hence index is
-1
if item[-1] not in dict:
dict[item[-1]]=1
else:
dict[item[-1]]+=1
#sorting the dictionary in descending order of the values
sort_dict=sorted(dict.items(),key=lambda x:x[1],reverse=True)
print("Busiest hour:",sort_dict[0][0])
#main program
#Reading customer details
n=int(input("Enter how many customers?(<=100) "))
#initializing empty list
client_list=[]
#reading the details of n customers
for i in range(0,n):
name=input("Enter the customer name:")
burger=input("Enter burger choice from this
list(A,B,C,D,E,F):")
time_of_purchase=input("Enter the time(10.00 am to 10.00
pm):")
total_bill=float(input("Enter the total bill amount:"))
#adding all the details as tuple to the list named
client_list
client_list.append((total_bill,name,burger,time_of_purchase))
#Function call
top3Spenders(client_list)
secondLowestBill(client_list)
busyHour(client_list)
Python code in IDLE pasted for better understanding of the indent.
Output Screen