我不知道该怎么问,但我的代码是:
class Bruch:
def __init__ (self,zaehler,nenner):
self.__zaehler=zaehler
self.__nenner=nenner
def __mul__ (self, other):
self.___zaehler *= other
self.__nenner *= other
def mal (self,other):
self.__zaehler *= other
self.__nenner *= other
def __str__(self):
return "Bruch : " + (self.__zaehler) + "/" + str(self.__nenner)
if __name__ == "__main__":
bruch1 = Bruch(2,3)
bruch2 = Bruch(4,5)
bruchMul = bruch1.mal(bruch2)
print bruchMul
bruchMul2 = bruch1*bruch2
print bruchMul2
当我运行它时,错误:
TypeError: unsupported operand type(s) for *=: 'int' and 'instance'
出现。在
谁能帮帮我吗。在
改变功能:
收件人:
^{2}$您希望返回一个新的Bruch而不更改当前的Bruch。在
相关问题 更多 >
编程相关推荐