-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclase_0_helper.py
60 lines (56 loc) · 1.94 KB
/
clase_0_helper.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
48
49
50
51
52
53
54
55
56
57
58
59
60
def suma(a,b):
salida = a + b
return salida
def function1(a,b,c=50,d="default"):
if type(a) == str and type(b)== str :
print(a + b + d)
else:
print(a + b + c)
return d
class ComplexNumbers:
def __init__(self,real, imag):
self.real = real
self.imag = imag
def print(self):
print(f'La parte real es {self.real} y la parte imaginaria es {self.imag}')
def set_real(self,real):
self.real = real
def set_imag(self,imag):
self.imag = imag
def suma(self, complex_number):
self.real = self.real + complex_number.real
self.imag += complex_number.imag
def __mul__(self,complex_number):
real = self.real*complex_number.real - self.imag*complex_number.imag
imag = self.real*complex_number.imag + self.imag*complex_number.real
output = ComplexNumbers(real, imag)
return output
def __add__(self,complex_number):
output = ComplexNumbers(
self.real+complex_number.real,
self.imag+complex_number.imag)
return output
def __repr__(self):
return f'La parte real es {self.real} y la parte imaginaria es {self.imag}'
class TriplexNumbers(ComplexNumbers):
def __init__(self, real, imag,tres):
super().__init__(real,imag)
self.tres = tres
def __repr__(self):
return f'La parte real es {self.real}, la parte imaginaria es {self.imag} y la parte tres es {self.tres}'
def __add__(self, number):
print("Is complex:", isinstance(number, ComplexNumbers))
print("Is triplex:", isinstance(number, TriplexNumbers))
if not isinstance(number,TriplexNumbers):
output = super().__add__(number)
else:
output = TriplexNumbers(
self.real+number.real,
self.imag+number.imag,
self.tres+number.tres,
)
return output
if __name__ == "__main__":
a = 4
b = 5
print(a+b)