Answer to Question #292103 in Python for Maryam

Question #292103

Zoya parents run a small bakery. They currently do billing manually. Zona decides to help




them by writing a small python program that takes as input the number of each item bought and




prints the total bill amount and change due.




You can create your own 5 items that are sold at the bakery and the price per unit of each item




(get creative!).




The program would ask for the number of each item that the customer is buying, assume that




they will enter 0 for items that the customer is not buying, and print the total amount. Then ask




for the amount the customer hands in and print any change due.




The program should:




● Change any negative numbers input to 0 (for number of item)




● Tell if the amount customer handed in is less than total (and how much the customer still




owes them)

1
Expert's answer
2022-01-30T07:24:03-0500
prices = {'donuts': 0.5, 'croissants': 0.9, 'cookies': 0.4, 'bread': 1.2, 'pies': 2.4}
total = 0
for key, value in prices.items():
    qty = int(input(f'Enter number of {key}: '))
    total += max(qty, 0) * value
print('Total bill: ${0:.2f}'.format(total))
paid = float(input('Enter amount paid by customer: '))
if paid < total:
    print('Customer still owes: ${0:.2f}'.format(total - paid))
elif paid > total:
    print('Change due: ${0:.2f}'.format(paid - total))
else:
    print('Bill paid!')

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS