← Back to Question List
Python Quiz #47
When Greedy Change Fails
Greedy change-making takes the largest coin that still fits at every step. With coins worth 1, 3 and 4, what does the greedy program below produce for 6, and what does that show?
📄 Code
1coins: list[int] = [4, 3, 1]2amount: int = 63used: list[int] = []4for coin in coins:5 while amount >= coin:6 used.append(coin)7 amount = amount - coin8print(used)