-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplex_number.py
More file actions
37 lines (28 loc) · 829 Bytes
/
complex_number.py
File metadata and controls
37 lines (28 loc) · 829 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
'''
A complex number is a number that can be expressed in the form a + bi, where a and b are real numbers and i is the imaginary unit.
Create class Complex with attributes, constructors and getters/setters.
'''
class Complex:
type = 'i'
def __init__(self, a, b):
self.a = a
self.b = b
def getComplex(self):
complex_num = f"{self.a + self.b}{self.type}"
return complex_num
def get_a(self):
return self.a
def get_b(self):
return self.b
def set_a(self, a):
self.a = a
def set_b(self, b):
self.b = b
my_complex = Complex(3, 1.222222)
print(my_complex.getComplex())
my_complex.set_a(0.00004)
my_complex.set_b(999)
print(my_complex.getComplex())
my_complex.set_a(12.12)
print(my_complex.get_a())
print(my_complex.get_b())