#!/usr/bin/python
#
_*_coding:utf8_*_
class money():
def __init__(self,currency,value,accuracy):
self.currency=currency
self.value=value
self.accuracy=accuracy
def __add__(self,other):
return money(self.currency,self.value+other.value,self.accuracy)
def __sub__(self,other):
return money(self.currency,self.value-other.value,self.accuracy)
def __rmul__(self,other):
return money(self.currency,self.value*other.value,self.accuracy)
# def __rmul__(self,other):
#
return self.value*other
rmbAccuracy=["","",""]
rmb1=money("rmb",20,rmbAccuracy)
rmb2=money("rmb",50,rmbAccuracy)
accRmb = rmb1 + rmb2
subRmb = rmb1 - rmb2
print "重载和为:"+str(accRmb.value)+"重载之差:"+str(subRmb.value)
mulRmb = rmb1 * rmb2 * rmb1
print "类的重载乘积为:"+str(mulRmb.value)
#mulIntRmb = rmb1 *28
#
print "类与整数的乘积为" +str(mulIntRmb)

相关文章:

  • 2022-12-23
  • 2022-01-17
  • 2021-06-15
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
猜你喜欢
  • 2021-08-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-29
  • 2021-11-12
  • 2022-12-23
相关资源
相似解决方案