# Title: Quadratic equation roots
# Heading: Python Program to Find the Roots of a Quadratic Equation
# Level: beginner
# Tags: quadratic equation, roots, discriminant, cmath, complex numbers
# About: Finds the roots of ax² + bx + c = 0 from the discriminant: two real roots, one repeated root, or two complex roots.

import cmath
import math


def quadratic_roots(a, b, c):
    """The roots of a*x**2 + b*x + c = 0, in a list."""
    discriminant = b ** 2 - 4 * a * c
    if discriminant == 0:
        return [-b / (2 * a)]  # one repeated root
    if discriminant > 0:
        root = math.sqrt(discriminant)  # two real roots
    else:
        root = cmath.sqrt(discriminant)  # two complex roots
    return [(-b + root) / (2 * a), (-b - root) / (2 * a)]


print("x^2 - 5x + 6 = 0:", quadratic_roots(1, -5, 6))
print("x^2 + 2x + 1 = 0:", quadratic_roots(1, 2, 1))
print("x^2 + 2x + 5 = 0:", quadratic_roots(1, 2, 5))
