forked from hyemileee/complex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex.py
More file actions
39 lines (32 loc) · 794 Bytes
/
Copy pathcomplex.py
File metadata and controls
39 lines (32 loc) · 794 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
29
30
31
32
33
34
35
36
37
38
39
'''
최동근: maintainer
이기욱: addition,subtraction
이혜미: multiplication
'''
class Complex:
def __init__(self,re=0,im=0):
self.re = re
self.im = im
def __str__(self):
return str(self.re) + "+" + str(self.im) + "i"
def multiply(self, c1):
c = Complex()
c.re = self.re * c1.re - self.im * c1.im
c.im = self.re * c1.im + self.im * c1.re
return c
def add (self, c1):
c = Complex()
c.re = self.re + c1.re
c.im = self.im + c1.im
return c
def subtract (self, c1):
c = Complex()
c.re = self.re - c1.re
c.im = self.im - c1.im
return c
c1 = Complex(1,2)
print(c1)
c2 = Complex(2,3)
print(c1.add(c2))
print(c2.subtract(c1))
print(c1.multiply(c2))