-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.py
35 lines (27 loc) · 909 Bytes
/
main.py
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
29
30
31
32
33
34
35
class MyComplex:
def __init__(self, complex):
self.complex = complex
def __add__(self, other):
c = self.complex + other.complex
return "{0:.2f}{1:+.2f}i".format(c.real, c.imag + 0)
def __sub__(self, other):
c = self.complex - other.complex
return "{0:.2f}{1:+.2f}i".format(c.real, c.imag + 0)
def __mul__(self, other):
c = self.complex * other.complex
return "{0:.2f}{1:+.2f}i".format(c.real, c.imag + 0)
def __truediv__(self, other):
c = self.complex / other.complex
return "{0:.2f}{1:+.2f}i".format(c.real, c.imag + 0)
def mod(self):
return "{0:.2f}{1:+.2f}i".format(abs(self.complex), 0)
C = map(float, input().split())
D = map(float, input().split())
X = MyComplex(complex(*C))
Y = MyComplex(complex(*D))
print (X + Y)
print (X - Y)
print (X * Y)
print (X / Y)
print (X.mod())
print (Y.mod())