MCPcopy Create free account
hub / github.com/CodeWithHarry/The-Ultimate-Python-Course / Complex

Class Complex

Chapter 11 - PS/04_problem4.py:1–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Complex:
2 def __init__(self, r, i):
3 self.r = r
4 self.i = i
5
6 def __add__(self, c2):
7 return Complex(self.r + c2.r, self.i + c2.i)
8
9 def __mul__(self, c2):
10 real_part = self.r * c2.r - self.i * c2.i
11 imag_part = self.r * c2.i + self.i * c2.r
12 return Complex(real_part, imag_part)
13
14 def __str__(self):
15 return f"{self.r} + {self.i}i"
16
17
18

Callers 3

__add__Method · 0.85
__mul__Method · 0.85
04_problem4.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected