Question: At this point, we are ready to start using our ` Sandwich ` class objects! * * Solve it ! * * Create your own
At this point, we are ready to start using our Sandwich class objects!
Solve it
Create your own ComplexNumber class in the cell with the comment #sicomplexnumber
Complex numbers have a real and an imaginary part. The init method should therefore accept two numbers. Store the first as self.real and the second as self.imag.
Implement a conjugate method that returns the object's complex conjugate as a new ComplexNumber object Recall that $x a bi implies barx a bi$ where $barx$ is the complex conjugate of $x$
Add the following magic methods to your ComplexNumber class:
abs determines the output of the builtin abs function absolute value Implement abs so that it returns the magnitude of the complex number. Recall that $a bisqrta b$
Implement lt and gt so that ComplexNumber objects can be compared by their magnitudes. That is $a bic di$ if and only if $a bic di$ and so on
Add the following magic methods to your ComplexNumber class:
Implement eq and ne so that two ComplexNumber objects are equal if and only if they have the same real and imaginary parts.
Implement addsubmul and div appropriately. Each of these should return a new ComplexNumber object.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
