定义函数返回 ax2 + bx + c = 0 的两个解
# -*- coding: utf-8 -*-
import math
def quadratic(a, b, c):
s = b*b - 4*a*c
if a == 0:
x = -c / b
return x
elif s==0:
x = -b / 2*a
return x
elif s < 0:
return 'no anwser'
else:
x = (-b + math.sqrt(s)) / (2 * a)
y = (-b - math.sqrt(s)) / (2 * a)
return x, y