In mathematics, **a quadratic equation is a polynomial equation of the second degree in x.** It can be written in the standard form as **ax^2 + bx + c = 0, **where a, b, and c are constants, and x is the variable. The quadratic equation has at most two solutions,** which are called roots or zeros of the expression on its left-hand side. **In this blog post, we will discuss how to write a **Python program that computes the real roots of a given quadratic equation using the math library.**

**Table of Contents:**

- What is a quadratic equation?
- What is the discriminant of a quadratic equation?
- Algorithm to compute the real roots of a given quadratic equation.
- Python program to compute the real roots of a given quadratic equation using the math library.
- Conclusion.

#### | Learn Python at " Computer Courses - All in One" Free android app

**What is a quadratic equation?**

**A quadratic equation is a polynomial equation of the second degree in x.** It can be written in the standard form as **ax^2 + bx + c = 0, where a, b, and c are constants, and x is the variable.** The quadratic equation has at most two solutions, which are called roots or zeros of the expression on its left-hand side.

**What is the discriminant of a quadratic equation?**

The **discriminant of a quadratic equation is a mathematical expression** that is used to determine the nature of the roots of the quadratic equation. It is defined as** b^2 - 4ac,** where a, b, and c are the coefficients of the quadratic equation. If the discriminant is positive, the quadratic equation has two real roots. If the discriminant is zero, the quadratic equation has one real root. If the **discriminant is negative**, the quadratic equation has two complex roots.

### Algorithm to compute the real roots of a given quadratic equation:

- Read the values of a, b, and c from the user.

- Calculate the discriminant using the formula **b^2 - 4ac.**

- If the** discriminant is greater than zero, **calculate the two real roots using the formula** (-b + sqrt(discriminant)) / 2a and (-b - sqrt(discriminant)) / 2a.**

- If the **discriminant is equal to zero,** calculate the **one real root **using the** formula -b / 2a.**

- If the **discriminant is less than zero,** print that the **roots are complex.**

**| ****Python MCQ Programs Interview - Android app**

### Python program to compute the real roots of a given quadratic equation using the math library:

**Output:**

In this post, we have discussed **how to write a Python program that computes the real roots of a given quadratic equation using the math library. **The program takes the values of a, b, and c as input from the user and calculates the discriminant using the formula b^2 - 4ac. Depending on the value of the discriminant, the program calculates the real roots of the quadratic equation using the appropriate formula. We hope this blog post has been helpful in understanding how to compute the real roots of a given quadratic equation in Python using the math library.

**| Practical List - Python**

**FAQ: **Python program that COMPUTES THE REAL ROOTS OF A GIVEN QUADRATIC EQUATION.

**Q: What is a quadratic equation?**

A: A quadratic equation is a polynomial equation of the second degree in x. It can be written in the standard form as ax^2 + bx + c = 0, where a, b, and c are constants, and x is the variable.

**Q: What is the discriminant of a quadratic equation?**

A: The discriminant of a quadratic equation is a mathematical expression that is used to determine the nature of the roots of the quadratic equation. It is defined as b^2 - 4ac, where a, b, and c are the coefficients of the quadratic equation.

**Q: What are the roots of a quadratic equation?**

A: The roots of a quadratic equation are the values of x that satisfy the equation. For a quadratic equation in standard form, the roots can be calculated using the formula (-b ± √(b^2 - 4ac)) / 2a.

**Q: What is the output of the Python program?**

A: The output of the Python program depends on the input values of a, b, and c. If the discriminant is greater than zero, the program calculates two real roots. If the discriminant is equal to zero, the program calculates one real root. If the discriminant is less than zero, the program calculates two complex roots. The program then prints the roots of the quadratic equation.

## 0 Comments