forked from thisisshub/HacktoberFest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.py
More file actions
28 lines (22 loc) · 772 Bytes
/
complex.py
File metadata and controls
28 lines (22 loc) · 772 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
28
import math
# inheriting built-in Complex
class Complex(complex):
def __add__(self, no):
return Complex(complex.__add__(self, no))
def __sub__(self, no):
return Complex(complex.__sub__(self, no))
def __mul__(self, no):
return Complex(complex.__mul__(self, no))
def __truediv__(self, no):
return Complex(complex.__truediv__(self, no))
def mod(self):
return Complex(complex.__abs__(self))
def __str__(self):
return '{0:04.2f}{1:+04.2f}i'.format(self.real, self.imag+0)
# default code
if __name__ == '__main__':
c = map(float, input().split())
d = map(float, input().split())
x = Complex(*c)
y = Complex(*d)
print(*map(str, [x+y, x-y, x*y, x/y, x.mod(), y.mod()]), sep='\n')