Question: Create a Complex class to perform the processing. Use the following code template. import math class Complex(object): def __init__(self, real, imaginary): self.real = real self.imaginary
Create a Complex class to perform the processing. Use the following code template.
import math
class Complex(object): def __init__(self, real, imaginary): self.real = real self.imaginary = imaginary
def __add__(self, no): # enter your code here return Complex(real, imaginary)
def __sub__(self, no): # enter your code here return Complex(real, imaginary)
def __mul__(self, no): # enter your code here return Complex(real, imaginary)
def __div__(self, no): # enter your code here return Complex(real, imaginary)
def mod(self): # enter your code here return Complex(real, 0)
def __str__(self): # enter your code here return result
# put this code in a main method C = map(float, raw_input().split()) D = map(float, raw_input().split()) x = Complex(*C) y = Complex(*D) print ' '.join(map(str, [x+y, x-y, x*y, x/y, x.mod(), y.mod()]))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
