Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PreconditionError(Exception):
- pass
- class ComplexRootError(Exception):
- pass
- def solve(a, b, c):
- if not ((isinstance(a, float) or isinstance(a, int)) and (isinstance(b, float) or isinstance(b, int)) and (isinstance(c, float) or isinstance(c, int))):
- raise TypeError
- if a == 0:
- raise PreconditionError
- if b*b - 4*a*c < 0:
- raise ComplexRootError
- d = float((b*b - 4*a*c)**0.5)
- res = (-b - d) / (a * 2), (-b + d) / (a * 2)
- if res[0] == res[1]:
- return (res[0])
- else:
- return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement