monetary applications (et al)

Ian Holmes ianholmes01 at lycos.com
Thu Sep 19 16:39:12 CEST 2002


terry <tg5027 at citlink.net> wrote in message news:<mailman.1032383305.18515.python-list at python.org>...
> >>>>> Chris wrote:
> -------------------------------------------------
> 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'
> -------------------------------------------------

not that I want to do all your work for you but

>>> unitprice = money(100)
>>> qty = 2
>>> amount = qty * unitprice.name #as .name as the var that was assigned a value
>>> amount
200
>>> taxrate = 0.06
>>> taxedamount = qty * unitprice.name + (qty*unitprice.name)*taxrate
>>> taxedamount
212.0
>>>



More information about the Python-list mailing list