#!/usr/bin/env python3

import math
import sys

def solve_equation(a, b, c):
    """Solve quadratic or linear equations"""
    print(f"Solving: {a}x² + {b}x + {c} = 0")
    
    # Linear equation (a = 0)
    if a == 0:
        if b == 0:
            return "Infinite solutions" if c == 0 else "No solution"
        else:
            x = -c / b
            return f"Linear equation: x = {x:.4f}"
    
    # Quadratic equation
    discriminant = b*b - 4*a*c
    print(f"Discriminant = {discriminant}")
    
    if discriminant > 0:
        x1 = (-b + math.sqrt(discriminant)) / (2*a)
        x2 = (-b - math.sqrt(discriminant)) / (2*a)
        return f"Two real roots: x₁ = {x1:.4f}, x₂ = {x2:.4f}"
    elif discriminant == 0:
        x = -b / (2*a)
        return f"One real root: x = {x:.4f}"
    else:
        real_part = -b / (2*a)
        imag_part = math.sqrt(-discriminant) / (2*a)
        return f"Complex roots: x₁ = {real_part:.4f} + {imag_part:.4f}i, x₂ = {real_part:.4f} - {imag_part:.4f}i"

def main():
    """Test cases"""
    test_cases = [
        (1, -3, 2),   # Two real roots
        (1, 2, 1),    # One real root
        (1, 0, 1),    # Complex roots
        (0, 2, -4),   # Linear equation
        (0, 0, 0),    # Infinite solutions
        (0, 0, 5)     # No solution
    ]
    
    print("=== PYTHON EQUATION SOLVER ===")
    for i, (a, b, c) in enumerate(test_cases, 1):
        print(f"\nTest case {i}:")
        result = solve_equation(a, b, c)
        print(result)

if __name__ == "__main__":
    main()
