Python Mini Project: Quadratic Equation

Enni Maedani
3 min readJan 2, 2022

--

Photo by Romka via Pexels

A quadratic equation is a polynomial equation with a second-order exponent. In this article, I will create a Python mini-project to determine the number and nature of roots for related quadratic equations.

First, let’s review the formula for finding the discriminant value. The discriminant value distinguishes the number of roots of the equation and is needed to solve quadratic equations. The discriminant has three properties:

  1. If the discriminant value is less than zero, there are no real roots and no solution to the quadratic equation.
  2. If the discriminant value is equal to zero, there is one real root (twin/similar). The formulas a, b, and c are required to find it.
  3. If the discriminant value is greater than zero, there are two different real roots, and the formulas a, b, and c are required to find them.

After understanding the conditions related to the discriminant formula, we can start the coding process.

Import “math” Module

First, we need to import the math module, as it will be used to find related quadratic roots.

Create Variables “a, b, and c”

After importing math, we create variables a, b, and c, which will be filled with the numbers we want to work on. These variables will be used to calculate the discriminant formula and find the quadratic roots.

Create a Formula for Finding the Discriminant Value

Next, we create a variable d to find the discriminant value by entering the formula d = b**2–4ac.

Using the “If” Function

The next step is to use the if function to enter the properties of the discriminant so that the quadratic roots can be known.

After completing the coding process, run it.

Testing the Quadratic Equation Formula

We can enter values for variable a. Let’s try entering the number 1.

Next, for variable b, let’s enter the number -5, and for variable c, we enter the number 6. Then, the result is as follows:

To check other quadratic equation properties, we can try entering variables a = 2, b = 4, and c = 2. The result will be as follows:

Next, with a = 1, b = 1, c = 9, the results are:

That’s all for this Python mini-project. If you have any suggestions or criticisms regarding this article, please do not hesitate to send them. Thank you :)

--

--

Enni Maedani

A room of my curiosity, ideas, perspectives, concerns, and a dash of my knowledge.