Discuss / Python / 作业

作业

Topic source
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')
if a == 0:
   raise TypeError('a不能等于0')
delta = b**2 - 4*a*c
if delta >= 0:    
    x = (-b + math.sqrt(delta)) / (2*a), (-b - math.sqrt(delta)) / (2*a)  
else:
    x = "此方程无实数解"
return x

  • 1

Reply