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 + li 3 + 5i 5 + 6i -1 - 4i...


Solve using Python3 and inheritance method


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 + li<br>3 + 5i<br>5 + 6i<br>-1 - 4i<br>def _add_(self, anotherRealINumber):<br>return self.number + anotherRealNumber.number<br>def _sub_(self, anotherRealNumber):<br>return self.number - anotherRealNumber.number<br>str_(self):<br>return str(self.number)<br>def<br>r1 = RealNumber(3)<br>r2 = RealNumber(5)<br>print(r1+r2)<br>cn1 = ComplexNumber(2, 1)<br>print(cn1)<br>cn2 = ComplexNumber(r1, 5)<br>print(cn2)<br>cn3 = cn1 + cn2<br>print(cn3)<br>cn4 = cn1 - 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 + li 3 + 5i 5 + 6i -1 - 4i def _add_(self, anotherRealINumber): return self.number + anotherRealNumber.number def _sub_(self, anotherRealNumber): return self.number - anotherRealNumber.number str_(self): return str(self.number) def r1 = RealNumber(3) r2 = RealNumber(5) 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