Task - 2 Write the ComplexNumber class so that the following code generates the output below. class RealNumber: OUTPUT: def _init_(self, number=0): self.number = number 8. 2 + 1i def Ladd_(self,...


please solve in python languange and use proper comments for better understanding . Thank you.


Task - 2<br>Write the ComplexNumber class so that the following code generates the output<br>below.<br>class RealNumber:<br>OUTPUT:<br>def _init_(self, number=0):<br>self.number = number<br>8.<br>2 + 1i<br>def<br>Ladd_(self, anotherRealNumber):<br>3 + 5i<br>return self.number + anotherRealNumber.number<br>5 + 6i<br>def _sub_(self, anotherRealNumber):<br>-1 - 4i<br>return self.number - anotherRealNumber.number<br>def _str_(self):<br>return str(self.number)<br>RealNumber(3)<br>RealNumber(5)<br>r1 =<br>r2 =<br>print(r1+r2)<br>cn1 = ComplexNumber(2, 1)<br>print(cn1)<br>cn2 =<br>ComplexNumber(r1, 5)<br>print(cn2)<br>cn3 = cn1 + cn2<br>print(cn3)<br>cn4 = cn1<br>cn2<br>print(cn4)<br>

Extracted text: Task - 2 Write the ComplexNumber class so that the following code generates the output below. class RealNumber: OUTPUT: def _init_(self, number=0): self.number = number 8. 2 + 1i def Ladd_(self, anotherRealNumber): 3 + 5i return self.number + anotherRealNumber.number 5 + 6i def _sub_(self, anotherRealNumber): -1 - 4i return self.number - anotherRealNumber.number def _str_(self): return str(self.number) RealNumber(3) RealNumber(5) r1 = r2 = print(r1+r2) cn1 = ComplexNumber(2, 1) print(cn1) cn2 = ComplexNumber(r1, 5) print(cn2) cn3 = cn1 + cn2 print(cn3) cn4 = cn1 cn2 print(cn4)

Jun 06, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here