Discuss / Python / 百度了下一元二次方程的球根公式

百度了下一元二次方程的球根公式

Topic source

叫我玮仔

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

def quadratic(a, b, c):
    for x in (a,b,c):
        if not isinstance(x,(int,float)):
            raise TypeError("类型错误!")
    if a==0:
        return 0-c/b
    d=math.sqrt(b*b*1.0-4*a*c)
    return (0-b+d)/(a*2),(0-b-d)/(a*2)

  • 1

Reply