class complex

This commit is contained in:
Mert Gör ☭ 2023-06-25 15:37:58 +03:00
parent 440b888c47
commit 8fe89e0d94
No known key found for this signature in database
GPG Key ID: 2100A876D55B39B9
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
class Complex:
def __init__(self, real = 0, imag = 0):
self.real = real
self.imag = imag
def disp(self):
print('{}+{}i'.format(self.real, self.imag))
def add(self, z):
result = Complex()
result.real = self.real + z.real
result.imag = self.imag + z.imag
return result
z1 = Complex(10, 20)
z2 = Complex(3, 4)
z3 = z1.add(z2)
z1.disp()
z2.disp()
z3.disp()