"""
Divide a given amount into bills and coins using a greedy algorithm.
This program is written in idiomatic Python, using built‑in functions,
clear structure, and full explanations.
"""
def divide_amount(amount, denominations):
"""
Given an amount and a list of bills/coins, print how many
of each denomination are needed using a greedy algorithm.
The greedy method is optimal for standard currency systems.
"""
print(f"Dividing amount: {amount}\n")
for d in denominations:
count = amount // d # integer division
if count > 0:
print(f"{d}-unit: {count}")
amount %= d # reduce remaining amount
if amount > 0:
print(f"\nWarning: leftover amount = {amount}")
def main():
bills_coins = [500, 100, 200, 50, 20, 10, 5, 2, 1]
# Python: sort descending using sorted()
denominations = sorted(bills_coins, reverse=True)
amount = 9749
divide_amount(amount, denominations)
if __name__ == "__main__":
main()
"""
run:
Dividing amount: 9749
500-unit: 19
200-unit: 1
20-unit: 2
5-unit: 1
2-unit: 2
"""