Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import math as cmath , funkcje
  2.  
  3. class ZlaPodstawa(Exception):
  4. def __init__(self):
  5. pass
  6.  
  7. def __str__(self):
  8. return "Zla podstawa logarytmu"
  9.  
  10.  
  11. class ZlyArgument(Exception):
  12. def __init__(self):
  13. pass
  14.  
  15. def __str__(self):
  16. return "Zly argument logarytmu"
  17.  
  18.  
  19. class RoznePodstawy(Exception):
  20. def __init__(self):
  21. pass
  22.  
  23. def __str__(self):
  24. return "Rozne podstawy"
  25.  
  26.  
  27. class Logarytm:
  28. def __init__(self, podstawa, argument):
  29. if podstawa <= 0 or podstawa == 1:
  30. raise ZlaPodstawa()
  31. if argument <= 0:
  32. raise ZlyArgument()
  33.  
  34. self.podstawa = podstawa
  35. self.argument = argument
  36.  
  37. def __add__(self, other_log):
  38. if self.podstawa != other_log.podstawa:
  39. raise RoznePodstawy()
  40. return Logarytm(self.podstawa, self.argument * other_log.argument)
  41.  
  42. def __str__(self):
  43. return 'log%d(%d)' % (self.podstawa, self.argument)
  44.  
  45. def redukuj(self):
  46. p = funkcje.liczba_i_wykladnik(funkcje.czynniki_pierwsze(self.podstawa))
  47. self.podstawa = p[0]
  48. self.argument = cmath.ceil(cmath.pow(self.argument, 1.0/p[1]))
  49.  
  50. def oblicz(self):
  51. return cmath.log(self.argument, self.podstawa)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement