To write a quadratic equation in Python, you can define a function that takes coefficients (a), (b), and (c) as parameters. You can then use the quadratic formula (x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}) to calculate the roots. Here’s a simple example:
<code class="language-python">import cmathdef quadratic_equation(a, b, c): discriminant = cmath.sqrt(b**2 - 4<em>a</em>c) root1 = (-b + discriminant) / (2<em>a) root2 = (-b - discriminant) / (2</em>a) return root1, root2
<h1>Example usage:</h1>roots = quadratic_equation(1, -3, 2) print(roots) # Output: (2.0, 1.0) </code>
Copyright © 2026 eLLeNow.com All Rights Reserved.