In: Computer Science
PYTHON 3 Your team has been hired by the new burgers place called “The hungry snake.” 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. 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
CODE
SOLUTION
//OUTPUT
//COPYABLE CODE
f = open("a.csv","w")
input1 = '''clientname, burgername, time_of_the_day,
totalbill
david sharmamari,burger1,10:00 am,100
david sharmamari,burger1,11:00 am,100
david sharmamari,burger1,12:00 am,100
david sharmamari,burger1,1:00 pm,100
david sharmamari,burger1,2:00 pm,100
david sharmamari,burger1,3:00 pm,100
sharmi,burger2,10:00 am,300
sharmi,burger2,11:00 am,300
sharmi,burger2,12:00 am,300
sharmi,burger2,12:30 am,300
Hasuu,burger3,12:30 am,500
sharmi,burger3,12:30 am,500
mano,burger4,12:30 am,900
devi,burger4,12:30 am,900
Ranju,burger3,12:30 am,500
mano,burger5,12:30 am,90
devi,burger5,12:30 am,90
Ranjetha,burger5,12:30 am,90
Manogar,burger6,1:30 pm,10
Robertshar,burger6,1:30 pm,10
Manivannan Bahaji Mohammad shar,burger1,12:30 am,500'''
f.write(input1)
f.close()
#coding part
n = 5
f = open("a.csv")
input1 = f.read().split("\n")
f.close()
input1 = input1[1:]
da = []
for i in input1:
da.append(i.split(","))
#print customer details
print("\nclient number for name ",n," is : ",da[n][0])
# longest name with client data
max_name = da[0][0]
for i in da:
if len(i[0]) > len(max_name):
max_name = i[0]
print("\nThe client with the longest name : ",max_name)
# seling burgers
burger_Cnt =
{"burger1":0,"burger2":0,"burger3":0,"burger4":0,"burger5":0,"burger6":0}
for i in da:
burger_Cnt[i[1]] = burger_Cnt[i[1]] + 1
burger_Cnt = sorted(burger_Cnt.items(), key=lambda x1: x1[1],
reverse=True)
print("\nTop selling burgers are : ")
print("1. ",burger_Cnt[0][0]," with the count of burgers :
",burger_Cnt[0][1])
print("2. ",burger_Cnt[1][0]," with the count of burgers :
",burger_Cnt[1][1])
print("3. ",burger_Cnt[2][0]," with the count of burgers :
",burger_Cnt[2][1])
# 1. top three client
bill_Cnt = {}
for i in da:
if i[0] in bill_Cnt:
bill_Cnt[i[0]] = int(bill_Cnt[i[0]]) + int(i[-1])
else:
bill_Cnt[i[0]] = int(i[-1])
bill_Cnt = sorted(bill_Cnt.items(), key=lambda x1: x1[1],
reverse=True)
print("\nTop three Clients :")
print("1. ",bill_Cnt[0][0]," with the bill amount :
",bill_Cnt[0][1])
print("2. ",bill_Cnt[1][0]," with the bill amount :
",bill_Cnt[1][1])
print("3. ",bill_Cnt[2][0]," with the bill amount :
",bill_Cnt[2][1])
# 2. lowest bill
print("\n lowest bill : ",bill_Cnt[-2][0])
# 3. Busiest day
hours_Cnt ={}
for i in da:
hour = i[2].split(":")
hour = hour[0]+ hour[1][-2:]
if hour in hours_Cnt:
hours_Cnt[hour] = int(hours_Cnt[hour]) + 1
else:
hours_Cnt[hour] = 1
hours_Cnt = sorted(hours_Cnt.items(), key=lambda x1: x1[1],
reverse=True)
print("\nBusiest day : ",hours_Cnt[0][0]," With number of customers
: ",hours_Cnt[0][1])
# Best hour
sales_Cnt = {}
total_Sales = 0
for i in da:
hour = i[2].split(":")
hour = hour[0]+ hour[1][-2:]
if hour in sales_Cnt:
sales_Cnt[hour] = int(sales_Cnt[hour]) + int(i[-1])
else:
sales_Cnt[hour] = int(i[-1])
total_Sales = total_Sales + int(i[-1])
sales_Cnt = sorted(sales_Cnt.items(), key=lambda x1: x1[1],
reverse=True)
print("\nBest sales hour : ",sales_Cnt[0], "With the tatal sales in
the hour : ",sales_Cnt[0][1])
# total sales
print("\nTotal sales : ",total_Sales)