Discuss / Python / 作业

作业

Topic source

达仔hongda

#1 Created at ... [Delete] [Delete and Lock User]

# 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))


  • 1

Reply