DefnameofBestCustomer(Sales, Customers)
that returns the name of the customer with the largest sale.
Write a program that prompts the cashier to enter all sales and customers, adds them to two lists, calls the function that you implemented, and displays the result. Use a sales of 0 as a sentinel.
Loop
Enter customer:
Enter Sales:
Store these in 2 lists
Call function nameofBestCustomer
Print the name of the best customer
Python, keep it simple
Hey mate, the code for above program is provided below. Here I have used some built-in list methods (i.e. append(), max(), index() ) to make the program small and simple, make sure you have an idea about what these methods returns and what is their work.
If you are not familiar with them or want to recall them, then do check the method's information and syntax given below -
1. append(): Used for appending and adding
elements to List. It is used to add elements to the last position
of List.
Syntax:
list.append(element)
2. max(): Calculates and returns maximum of all
the elements of List.
Syntax:
max(list)
3. index(): Returns the index of element
present in the list. If there are more than one occurence of any
element in the list then it returns the index of first
occurrence.
Syntax:
list.index(element)
Do refer the screenshot of the code for proper indentation and error free execution.
PROGRAM -
sales=list()
customer=list()
def nameofBestCustomer(Sales,Customers):
max_sales=Sales.index(max(Sales))
return Customers[max_sales]
while True:
c=input("\nEnter Customer: ")
customer.append(c)
s=int(input("Enter Sales: "))
sales.append(s)
if s==0:
break
best_customer=nameofBestCustomer(sales,customer)
print("\n\nName of the best customer is: " + best_customer)
SAMPLE OUTPUT -
Get Answers For Free
Most questions answered within 1 hours.