Discuss / Python / 我已经忘了方程是什么了

我已经忘了方程是什么了

Topic source

夏蝉live

#1 Created at ... [Delete] [Delete and Lock User]
import math
#2元1次方程解法
#判断 b^2-4ac;解法 (-b[+-]math.sqrt(b^2-4ac))/2a 
def quadratic(a, b, c):
    tmp = b**2-4*a*c 
    if tmp < 0 : return None
    if a==0 : return False
    return (-b+math.sqrt(tmp))/(2*a),(-b-math.sqrt(tmp))/(2*a)

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

  • 1

Reply