If your file is running with no errors, override the method __mul__ in the Real class so it returns a Real object when an instance of the Real class is multiplied by another Real object, an integer or a float, and a Complex object when multiplied by an instance of the Complex class. Once again, if you need to call a method in the Complex class, remember you shouldn’t be cutting and pasting code! -- If your file is running with errors, seek assistance from a TA or your recitation partner before proceeding with your implementation. You can test your implementation using this short example: >>> x = Real(3) >>> y = Real(8) >>> z = Complex(2, 5) >>> op1 = x * y >>> print(op1) 24 + 0i >>> type(op1) <class '__main__.Real'> >>> op2 = x * 2 >>> print(op2) 6 + 0i >>> type(op2) <class '__main__.Real'> >>> op3 = 2 * y >>> print(op3) 16 + 0i >>> type(op3) <class '__main__.Real'> >>> op4 = x * z >>> print(op4) 6 + 15i >>> type(op4) <class '__main__.Complex'> What OOP Principle(s) are you using in this implementation?多项选择题
登录即可查看完整答案
我们收录了全球超50000道真实原题与详细解析,现在登录,立即获得答案。
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!