-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplex.py
More file actions
27 lines (20 loc) · 743 Bytes
/
Copy pathComplex.py
File metadata and controls
27 lines (20 loc) · 743 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import math
class ComplexNum:
def __init__(self):
self.real = float(input('Enter the real value: '))
self.img = float(input('Enter the imaginary value: '))
def absolute(self):
abs = math.sqrt(self.real ** 2 + self.img ** 2)
return abs
def __add__(self, A):
return complex(A.real + self.real, A.img + self.img)
def __mul__(self, A):
return complex(A.real * self.real - A.img * self.img, A.real
* self.img + A.img * self.real)
def main():
c1 = ComplexNum()
c2 = ComplexNum()
print ('Product of complex numbers = ', c1 * c2)
print ('Sum of the complex numbers =', c1 + c2)
if __name__ == '__main__':
main()