-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
47 lines (31 loc) · 741 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
36
37
38
39
40
41
42
43
44
45
46
47
from math import sqrt
class complex:
def __init__(self, x ,y):
self.x = x
self.y = y
def add(self):
return number(self.x.r+self.y.r, self.x.im+self.y.im).show()
def multi(self):
return number( self.x.r*self.y.r-self.x.im*self.y.im, self.y.r*self.x.im+self.x.r*self.y.im).show()
class number:
def __init__(self, x, y):
self.r = x
self.im = y
def show(self):
print self.r,self.im
def negation(self):
self.r = self.r*-1
self.im = self.im*-1
return self
def inversion(self):
root = sqrt(self.r*self.r + self.im*self.im)
self.r = (self.r/root)
self.im = -(self.im/root)
return self
n1 = number(3,2)
n2 = number(1,1)
n1.negation().show()
n1.inversion().show()
c = complex(n1,n2)
c.add()
c.multi()