Guest User

Untitled

a guest
Sep 19th, 2019
97
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class C:
  2. def __init__(self, real, imag):
  3. self.real = real
  4. self.imag = imag
  5.  
  6. def getC(self):
  7. print(complex(self.real, self.imag))
  8.  
  9. def sumC(self, b):
  10. real = self.real + b.real
  11. imag = self.imag + b.imag
  12. return C(real, imag)
  13.  
  14. def razC(self, b):
  15. real = self.real - b.real
  16. imag = self.imag - b.imag
  17. return C(real, imag)
  18.  
  19. def umnC(self, b):
  20. real = self.real * b.real - self.imag * b.imag
  21. imag = self.real * b.imag + self.imag * b.real
  22. return C(real, imag)
  23.  
  24. def delC(self, b):
  25. real = (self.real * b.real + self.imag * b.imag) / (b.real ** 2 + b.imag ** 2)
  26. imag = (self.imag * b.real - b.imag * self.real) / (b.real ** 2 + b.imag ** 2)
  27. return C(real, imag)
  28.  
  29.  
  30. a = C(2, 3)
  31. b = C(1, 2)
  32.  
  33. s = a.sumC(b)
  34. s.getC()
  35.  
  36. r = a.razC(b)
  37. r.getC()
  38.  
  39. u = a.umnC(b)
  40. u.getC()
  41.  
  42. d = a.delC(b)
  43. d.getC()
RAW Paste Data