Discuss / Python / 有点懵

有点懵

Topic source

-- coding: utf-8 --

import math

def quadratic(a,b,c): if a==0: raise TypeError('分母能不为零')

elif b*b - 4*a*c ==0:
    return (-b + math.sqrt(b*b - 4*a*c))/(2*a)

numerator1 = (-b + math.sqrt(b*b - 4*a*c))/(2*a)
numerator2 = (-b - math.sqrt(b*b - 4*a*c))/(2*a)
return numerator1,numerator2

print(quadratic(2,3,1)) print(quadratic(1,3,-4))


  • 1

Reply