Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sprint 9:18 PM ggc.view.usg.edu Continue the fruit_stand.py program. It should p

ID: 3737095 • Letter: S

Question

Sprint 9:18 PM ggc.view.usg.edu Continue the fruit_stand.py program. It should prompt the vendor for custome names, and then for each customer calculate the total. The program should only stop once the vendor types "done" for a customer name. The following is an example. Your program must first prompt the vendor for th fruit names and prices (see parts 1, 2) before prompting for customer names an fruit quantities PS C:UsersissivalDesktop> python fruit_stand.py Enter a fruit name (or done): Mango Enter a fruit name (or done): Strawberry Enter a fruit name (or done) Kiwi Enter a fruit name (or done): done Enter the price for Mango: 2.54 Enter the price for Strawberry: 0.23 Enter the price for Kiwi: .75 Enter customer name (or done): Bob Mango($2.54) Quantity: 3 Strawberry $0.23) Quantity: 10 Kiwi(s0.75) Quantity: 2 Bob's total purchase is 11.42 Enter customer name (or done): Lisa Mango ($2.54) Quantity: 10 Strawberry ($0.23) Quantity: 40 Kiwi ($0.75) Quantity: 20 Lisa's total purchase is $49.6 Enter customer name (or done): Sam Mango($2.54) Quantity: 0 Strawberry ($0.23) Quantity:0 Kiwi ($0.75) Quantity: 1 Sam's total purchase is so.75 Enter customer name (or done): done PS C:Users ssivaDesktop> Submit the fruit_stand.py file in the FruitStandProject_Part4 dropbox.

Explanation / Answer

# note the indentation is crucial for the program to work correctly
# create a dict which can store the key-value pair of fruit and it's price
fruitDict = {};

# collect fruit names from input
fruitName = "";
while fruitName != "done":
fruitName = input("Enter a fruit name (or done): ");
if fruitName != "done":
# store it in the fruitDict initialized above
fruitDict[fruitName] = 0;
print(); # to print a blank line

# collect fruit prices from input by looping over the fruitDict
price = 0.0;  
for key in fruitDict:
price = input("Enter the price for " + key + ": ");
# store it against the same fruit key in the fruitDict
fruitDict[key] = price;
print(); # to print a blank line

# collect the customer names & the quantity required for each fruit
customerName = "";
quantity = 0;
total = 0.0; # total purchase price for the customer
while customerName != "done":
customerName = input("Enter customer name (or done): ");
if customerName != "done":
# get quantity required for each fruit
for key in fruitDict:
# fruitDict[key] will need to be cast to float, so that the value .75 can be printed as 0.75
quantity = input(key + "($" + str(float(fruitDict[key])) + ") Quantity: ");
price = float(fruitDict[key]);
# sum up the price for each fruit
total = total + (int(quantity) * price);
# print the customer's total price  
print(); # to print a blank line
print (customerName + "'s total purchase is $" + str(total));  
print(); # to print a blank line

  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote