Discuss / Python / 交作业,请大家批评指正!

交作业,请大家批评指正!

Topic source

def quadratic(a, b, c):

if not isinstance(a,(int, float)):#先进行参数类型检查

raise TypeError('the bad operand type of a')

elif not isinstance(b,(int, float)):

raise TypeError('the bad operand type of b')

elif not isinstance(c,(int, float)):

raise TypeError('the bad operand type of c')

elif (b**2) - (4*a*c) < 0:

return "此方程无解"

else:

x1 = ((-b) + math.sqrt(((b**2) - (4 * a *c))))/(2*a)

x2 = ((-b) - math.sqrt(((b**2) - (4 * a *c))))/(2*a)

return x1, x2


  • 1

Reply