Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

# program to calculate the total grocery cost of Uber customers def main () # function to display author and submission details def display Detail

# program to calculate the total grocery cost of Uber customers

def main ()

# function to display author and submission details def display Detail ():

print("Author: XYZ")

print("Class: N/A")

print("Date: 2023-02-12") \

# function to calculate the total cost for a customer

def calculate cost(name):

# list of grocery items and their prices

groceries = {"apple": 0.5, "banana": 0.25, "carrot": 0.75, "date": 1.0, "elderberry": 1.5}

total Cost = 0

# display menu and get customer's order

print(" Grocery Menu:")

for item in groceries:

print(f"{item}: ${groceries[item]}") print(" ")

for item in groceries: while True: try: order = int(input(f"How many {item} would you like to purchase, {name}? ")) if order >= 0: break else: print("Invalid input. Order should be 0 or more.") except print("Invalid input. Order should be a positive integer.") totalCost += order * groceries[item]

# display the customer's total bill

print(f" {name}'s total bill: ${totalCost}")

return total cost #

list of customer names customer names = ["Alice", "Bob", "Charlie", "Daisy"]

total bill = 0

# iterate through customer names and calculate total bill

display details()

for name in customer names: bill = calculate cost(name) total bill += bill

# calculate Uber's commission (10% of the total bill)

commission = total bill * 0.1 # display total bill and Uber's commission

print(f" Total bill for all customers: ${totalBill}")

print(f"Uber's commission: ${commission}")

trying to put main () at the bottom to be able to run in the program needhelp

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Students also viewed these Databases questions

Question

What is the cerebrum?

Answered: 1 week ago