Without modulo or divmod:
cost = 51 paid = 100 coins = [50,20,10,5,2,1] change = [] for coin in coins: while (paid - cost) / coin >= 1: change.append(coin) paid -= coin print(change) print(sum(change))
Output:[20, 20, 5, 2, 2]
49
Yoriz write Oct-22-2022, 07:51 AM:
(Oct-21-2022, 09:04 AM)DPaul Wrote: I'm in two minds, because this is homework, and we are not supposed to ...
https://python-forum.io/misc.php?action=help&hid=52 Wrote:Homework and No Effort Questions
This forum is focused on education. It exists to help people learn Python. We don’t exist to solve others’ problems, although that tends to be a happy byproduct of education. You should keep this in mind when writing replies.
It is highly advised that you do not post the full solution, even if the asker is putting in the effort. It is better to use hints with natural language rather than code if at all possible. Only after the author has something complete you may go all out.
It is more important to do the right thing, than to do the thing right.(P.Drucker)
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.
Better is the enemy of good. (Montesquieu) = French version for 'kiss'.