Advertisement
Guest User

Untitled

a guest
May 26th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. class PreconditionError(Exception):
  2.     pass
  3.  
  4. class ComplexRootError(Exception):
  5.     pass
  6.  
  7. def solve(a, b, c):
  8.     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))):
  9.         raise TypeError
  10.     if a == 0:
  11.         raise PreconditionError
  12.     if b*b - 4*a*c < 0:
  13.         raise ComplexRootError
  14.     d = float((b*b - 4*a*c)**0.5)
  15.     res = (-b - d) / (a * 2), (-b + d) / (a * 2)
  16.     if res[0] == res[1]:
  17.         return (res[0])
  18.     else:
  19.         return res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement