Python Forum
Creating a change table - £0.01-£0.50?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating a change table - £0.01-£0.50?
#10
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'.
Reply


Messages In This Thread
RE: Creating a change table - £0.01-£0.50? - by DPaul - Oct-22-2022, 07:28 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  creating a 3x3 multiplication table aditvaddi 1 3,659 Jun-18-2018, 06:05 AM
Last Post: volcano63
  Tricky estimating three models and creating a table: regression HellinPython 1 2,843 Oct-18-2017, 02:46 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020