Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math as cmath , funkcje
- class ZlaPodstawa(Exception):
- def __init__(self):
- pass
- def __str__(self):
- return "Zla podstawa logarytmu"
- class ZlyArgument(Exception):
- def __init__(self):
- pass
- def __str__(self):
- return "Zly argument logarytmu"
- class RoznePodstawy(Exception):
- def __init__(self):
- pass
- def __str__(self):
- return "Rozne podstawy"
- class Logarytm:
- def __init__(self, podstawa, argument):
- if podstawa <= 0 or podstawa == 1:
- raise ZlaPodstawa()
- if argument <= 0:
- raise ZlyArgument()
- self.podstawa = podstawa
- self.argument = argument
- def __add__(self, other_log):
- if self.podstawa != other_log.podstawa:
- raise RoznePodstawy()
- return Logarytm(self.podstawa, self.argument * other_log.argument)
- def __str__(self):
- return 'log%d(%d)' % (self.podstawa, self.argument)
- def redukuj(self):
- p = funkcje.liczba_i_wykladnik(funkcje.czynniki_pierwsze(self.podstawa))
- self.podstawa = p[0]
- self.argument = cmath.ceil(cmath.pow(self.argument, 1.0/p[1]))
- def oblicz(self):
- return cmath.log(self.argument, self.podstawa)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement