Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in python, the different rest cases are provided 15 pts) Write the class Complex that supports the basic complex number operations. Such operations are addition
in python, the different rest cases are provided
15 pts) Write the class Complex that supports the basic complex number operations. Such operations are addition (+), subtraction (-), multiplication (*) and division (/) of complex numbers, and addition (+), subtraction and multiplication (*) of a complex by a scalar (float or int). All methods must return (not print) the result. Class also supports the rich comparison for equality ==) - Check the doctest for object behavior examples. - You must use the special methods for those 5 operators in order to override their behavior. - You will need other special methods to achieve a legible object representation (what you see when printing and returning the object). - Addition, subtraction and multiplication by scalar and by another complex number use the same operator, so you must check the type of the object in order to decide which operation you have to perform - Rich comparison returns a Boolean value The rest of the methods must return a new Complex object, this means the original objects should not change after the operation is performed. - Test your code, this is how you ensure you get the most credit out of your work!! - When performing an invalid operation, return None - You are not allowed to modify the constructor or any given code. Note that to support number (+,- or *) Complex, you are going to need 3 other special methods that can reuse code from the Complex (+,- or *) number operations. Hint: Section 3.3.1. Basic customization (e ) and Full Section 3.3.8. Emulating numeric types in https://docs.python.org/3/reference/datamodel.html#emulating-numeric-types class Complex: >>> a=Complex(5.2,-6) >>> b=Complex(2,14) >>> a+b (7.2, 8i) >>> a-b (3.2, -20i) >>> a*b (94.4, 60.8i) >>> a/b (-0.368, -0.424i) >>> b*5 (10, 70i) >>> 5*b (10, 70i) >>> 5+a (10.2, -6i) >>> a+5 (10.2, -6i) >>> 5-b (3, -14i) >>> b-5 (-3, 14i) >>> print(a) 5.2-6i >>> print(b) 2+14i >>> b (2, 14i) >>> isinstance(a+b, Complex) True >>> a. conjugate (5.2, 6i) >>> b. conjugate (2, -14i) >>> b==Complex(2,14) True >>> a==b FalseStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started