Old Man Yells At Cloud

Chris Angelico rosuav at gmail.com
Tue Sep 19 15:22:02 EDT 2017


On Wed, Sep 20, 2017 at 4:59 AM, Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> "Jan Erik =?utf-8?q?Mostr=C3=B6m?=" <lists at mostrom.pp.se> writes:
>>And I'm amazed how often I see people trying to calculate
>>change = sum handed over - cost
>>and then trying to figure out what bills/coins should be returned
>>instead of doing the simple thing of just adding to the cost.
>
>   I don't get this. For example, the contractual payment (cost) is
>
> 47.21
>
>   , the other party hands over
>
> 50.25
>
>   . Now I am supposed to add /what/ to the cost?

Start at the smallest end. You need to make 21 cents up to 25. So hand
back four pennies. Then make 47 dollars up to 50. Here in Australia,
that would mean a $1 coin and a $2 coin; in the US, probably three $1
notes. You count 'em off: starting at 47, hand a dollar, 48, another
dollar, 49, a third dollar, 50. Now you've added the change onto the
cost, reaching the amount paid.

It's more useful when the customer *hasn't* tried to be helpful; what
you're doing is rounding everything up to the next unit. I'm going to
assume pre-1992 Australian currency (when we still had 1c and 2c
coins) - feel free to adjust to your own. The cost is $47.21; the
customer handed over a $50 note. You say the parts in quotes.

* Quote the value of the bill. "Forty-seven dollars twenty-one."
* Build 21 cents up to 25. Two 2c coins: "23, 25"
* Build 25 cents up to 30. One 5c coin: "30"
* Build 30 up to 50. One 20c coin: "50"
* Build 50 up to the next dollar. One 50c coin: "48 dollars."
* Build that up to the amount paid. One $2 coin: "50."

Or of course you could use other denominations (maybe a pair of $1
coins if you're out of twos), in which case you'd say that
appropriately ("49, 50").

Does that make sense?

ChrisA



More information about the Python-list mailing list