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)
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!')
Comments
Leave a comment