Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Complex:
- def __init__(self, a, b):
- self.a = a
- self.b = b
- def addition(self, t):
- temp = Complex(0,0)
- temp.a = self.a + t.a
- temp.b = self.b + t.b
- return temp
- def subtraction(self, t):
- temp = Complex(0,0)
- temp.a = self.a - t.a
- temp.b = self.b - t.b
- return temp
- def multiplication(self, t):
- temp = Complex(0,0) # a = self.a #b = self.b
- temp.a = self.a * t.a - self.b * t.b # c = t.a #d = t.b
- temp.b = self.a * t.b + self.b * t.a
- return temp
- def division(self, t):
- temp = Complex(0,0)
- denominator = t.a ** 2 + t.b ** 2
- if denominator != 0:
- temp.a = (self.a * t.a + self.b * t.b) / denominator
- temp.b = (self.b * t.a - self.a * t.b) / denominator
- return temp
- else:
- return "Err"
- def print_Complex(self):
- if self.b < 0:
- print("{} - i({})".format(self.a, self.b*(-1)))
- else:
- print("{} + i({})".format(self.a, self.b))
- #------------------------------------------------------------------
- c1 = Complex(5,5)
- c2 = Complex(5,5)
- c_add = c1.addition(c2)
- c_add.print_Complex()
- c_sub = c1.subtraction(c2)
- c_sub.print_Complex()
- c_mult = c1.multiplication(c2)
- c_mult.print_Complex()
- c_div = c1.division(c2)
- c_div.print_Complex()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement