已经实施了一个名为ComplexNumbers
类,这是代表复数,我不允许使用内置的的类型了点。 我已经覆盖了运营商(__add__
,__sub__
,__mul__
,__abs__
,__str_
允许进行基本操作 但现在我只能和覆盖__div__
操作的Python司复数,而无需使用内建类型和运算符
允许使用:。
我“M使用float
表示该数字的虚部和float
代表相对部分
我已经尝试过:
- 我抬头看如何执行复杂的数字的分工(手写)
- 我曾经做过一个计算实例
- 思考如何以编程方式实现它没有任何好的结果
说明如何将复杂的数字:
http://www.mathwarehouse.com/algebra/complex-number/divide/how-to-divide-complex-numbers.php
我实现乘法:
def __mul__(self, other):
real = (self.re * other.re - self.im * other.im)
imag = (self.re * other.im + other.re * self.im)
return ComplexNumber(real, imag)
你不允许使用int吗? –
@PatrickHaugh我会更新实际部分的问题类型是'float'虚部的类型是'int' –
好吧,这就是您需要的所有东西。在划分算法中你遇到麻烦了吗? –