Files
jps/python/function_3.py

12 lines
314 B
Python
Raw Permalink Normal View History

# solves a quadratic equation in the form ax^2 + bx + c = 0
2020-02-17 11:58:19 -06:00
def solve_quadratic(a, b, c):
2020-02-17 11:59:34 -06:00
inside = b**2 - (4 * a * c)
2020-02-17 11:58:19 -06:00
if (inside < 0):
return None
elif (inside == 0):
return [-4/(2 * a)]
else:
return [(-b + inside**0.5) / (2 * a), (-b - inside**0.5) / (2 * a)]
print(solve_quadratic(1, 5, 6))