monetary applications (et al)
Michael Stenner
mstenner at phy.duke.edu
Wed Sep 18 17:27:13 EDT 2002
On Wed, Sep 18, 2002 at 05:35:32PM -0400, terry wrote:
> I do admit to being OO inhibited, so maybe you could take it from this
> short piece code and execution results, and, provide a brief
> description of what you would put into this money class that would
> eliminate this error message, while maintaining the code simplicity.
While you're at it, please write me 4-liner that predicts the stock
market's behavior. :)
Take a look at this:
http://python.org/doc/2.2.1/ref/numeric-types.html
for how to emulate numeric types.
-Michael
> -------------------------------------------------
> class money:
> def __init__(self,name):
> self.name = name
>
> unitprice = money(100)
> qty = 2
> amount = qty * unitprice
>
> terry at terry:~> python money.py
> Traceback (most recent call last):
> File "money.py", line 7, in ?
> amount = qty * unitprice
> TypeError: unsupported operand type(s) for *: 'int' and 'instance'
> -------------------------------------------------
>
> Support for mixed number types in expressions involving this money
> class must come from somewhere - where? And, it must be capable of
> determing and setting amount to be of class money to be consistent with
> the rest of Python's complexity hierarchy for the handling of numbers.
>
> The rest of the problem is that the above is a trivial calculation.
> What happens to your recommendation when faced with an additional
> number type?
>
> taxrate = 0.06
> amount = qty * unitprice + (qty*unitprice)*taxrate
>
> As I see it, if Python had an intrinsic number type of 'money', the
> logic for determing the results of the above calculation would be
> easily determined and consistent with expectations, as in VB.
>
> Thanks for your time,
>
> terry
>
> --
> http://mail.python.org/mailman/listinfo/python-list
--
Michael Stenner Office Phone: 919-660-2513
Duke University, Dept. of Physics mstenner at phy.duke.edu
Box 90305, Durham N.C. 27708-0305
More information about the Python-list
mailing list