# import math
def quadratic(a, b, c): if not isinstance(a, (int, float)): raise TypeError('bad operand type') if not isinstance(b, (int, float)): raise TypeError('bad operand type') if not isinstance(c, (int, float)): raise TypeError('bad operand type') n = b2-4ac if a == 0: return -1,c/b elif n < 0: return 0,0 else: return (-b + math.sqrt(b2-4ac))/(2a), (-b - math.sqrt(b**2-4ac))/(2a)
print('quadratic(2, 3, 1) =', quadratic(2, 3, 1)) print('quadratic(1, 3, -4) =', quadratic(1, 3, -4))
Sign in to make a reply
达仔hongda
# import math
def quadratic(a, b, c): if not isinstance(a, (int, float)): raise TypeError('bad operand type') if not isinstance(b, (int, float)): raise TypeError('bad operand type') if not isinstance(c, (int, float)): raise TypeError('bad operand type') n = b2-4ac if a == 0: return -1,c/b elif n < 0: return 0,0 else: return (-b + math.sqrt(b2-4ac))/(2a), (-b - math.sqrt(b**2-4ac))/(2a)
print('quadratic(2, 3, 1) =', quadratic(2, 3, 1)) print('quadratic(1, 3, -4) =', quadratic(1, 3, -4))