- class Complex():
- def __init__(self, a, b):
- self.a = a
- self.b = b
- def __add__(self, complex2):
- a_val = self.a + complex2.a
- b_val = self.b + complex2.b
- return Complex(a_val, b_val)
- def __sub__(self, complex2):
- a_val = self.a - complex2.a
- b_val = self.b - complex2.b
- return Complex(a_val, b_val)
- def __mul__(self, complex2):
- a_val = (self.a*complex2.a) - (self.b*complex2.b)
- b_val = (self.b*complex2.a) + (self.a*complex2.b)
- return Complex(a_val, b_val)
- def __eq__(self, complex2): #overloading equal operator
- if isinstance(complex2, Complex):
- return (self.a == complex2.a) and (self.b==complex2.b)
- else:
- return false
- def __lt__(self, complex2): #overloading less than operator
- return (self.a < complex2.a) and (self.b<complex2.b)
- def __le__(self, complex2):#overloading less than or equal operator
- return (self.a <= complex2.a) and (self.b<=complex2.b)
- def __gt__(self, complex2):#overloading greater than operator
- return (self.a > complex2.a) and (self.b>complex2.b)
- def __ge__(self, complex2):#overloading greater than or equal operator
- return (self.a >= complex2.a) and (self.b>=complex2.b)
- def __truediv__(self, complex2):
- a_val = ((self.a*complex2.a) + (self.b*complex2.b)) / (complex2.a**2) + (complex2.b**2)
- b_val = (self.b*complex2.a) + (self.a*complex2.b)
- return Complex(a_val, b_val)
- def __abs__(self):
- return (self.a**2+self.a**2)**0.5
- def __str__(self):
- return str(self.a)+"+i"+str(self.b)
- from Complex import Complex
- def main():
- input_line = input("Enter the first complex number: ")
- input_line = list(map(float,input_line.split()))
- a, b = input_line[0], input_line[1]
- c1 = Complex(a, b)
- input_line = input("Enter the second complex number: ")
- input_line = list(map(float,input_line.split()))
- a, b = input_line[0], input_line[1]
- c2 = Complex(a, b)
- print()
- print("c1 is", c1)
- print("c2 is", c2)
- print("|" + str(c1) + "| = " + str(abs(c1)))
- print("|" + str(c2) + "| = " + str(abs(c2)))
- print(c1, " + ", c2, " = ", c1 + c2)
- print(c1, " - ", c2, " = ", c1 - c2)
- print(c1, " * ", c2, " = ", c1 * c2)
- print(c1, " / ", c2, " = ", c1 / c2)
- print("Is c1 < c2?", c1 < c2)
- print("Is c1 <= c2?", c1 <= c2)
- print("Is c1 > c2?", c1 > c2)
- print("Is c1 >= c2?", c1 >= c2)
- print("Is c1 == c2?", c1 == c2)
- print("Is c1 != c2?", c1 != c2)
- print("Is c1 == 'Hello There'?", c1 == 'Hello There')
- print("Is c1 != 'Hello There'?", c1 != 'Hello There')
- main()
main 함수부분 제외하고 수정할 부분 있으
극혐 - dc App
넘어렵다 고수네
false => False고 나눗셈 좀 이상하네