Discuss / Python / 交作业

交作业

Topic source

import math def quadratic(a,b,c): for x in (a,b,c): if not isinstance(x,(int,float)): raise TypeError("输入错误") else: pass

delta=b*b-4*a*c
if a==0:
    raise TypeError("a should not be 0")
elif delta<0:
    return"no solution"
elif delta==0:
    return -b/2/a
else:
    return ((-b+math.sqrt(delta))/2/a,(-b-math.sqrt(delta))/2/a)

  • 1

Reply