---------- Forwarded message ---------- From: "Danny Yoo" <danny....@gmail.com> Date: Feb 2, 2016 1:22 PM Subject: RE: [Tutor] Finding the max value from a dictionary that does not exceed a variable's value. To: "Lawrence Lorenzo" <mcshiz...@hotmail.co.uk> Cc:
On Feb 2, 2016 10:34 AM, "Lawrence Lorenzo" <mcshiz...@hotmail.co.uk> wrote: > > > I can do it with a list, however I need to be able to print the change amount in coin names. Thanks for your reply sorry I didn't respond earlier I didn't see it until just now. > Just to expand on what I'm trying with this is to print an arbitrary value as 1p, 2p, 5p, 10p, 20p, 50p, £1 in the least amount required so if the change needed is £2.37 then the program prints that much as ("£1, £1, 20p, 10p, 5p, 2p") Consider separating the process of computing the answer from presentation of that answer. That is: just because you have to print or the coin names at the end doesn't mean you have to *compute* the change in terms of those string names. You can compute in terms of the numerical coin values first, and as a separate step, translate the answer back in terms of coin names when presenting the answer. Think of a problem where someone asks you to add two Roman numerals together. It would be madness to try to do that without first changing the representation into something more computer-friendly. Same line of reasoning. Choose the data representation to make the problem easy to solve. As long as we have a way to go back from that representation to something that's human readable, were good to go. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor