top of page
Search

A python program that will calculate the quadratic equation using formula method.

  • Writer: Nelson John
    Nelson John
  • Nov 14, 2017
  • 2 min read

In this post, I will show you how to write a python program that will calculate the quadratic equation using formula method. I discovered that so many students are having similar issues in the area of calculating the quadratic equation using a formula. In this practical, I will show you how to write a simple python program that will enable you calculate the quadratic equation using the formula without wasting much of our time. Below is the program.

You start by prompting the user to enter coefficients a,b,c

a = eval(input("Enter the coefficient of first term: ")) b = eval(input("Enter the coefficient of second term: ")) c = eval(input("enter the coefficient of third term: "))

The next step here is to compute the roots of the equation.

r1 = (-b + ((b ** 2) - (4 * a * c))**0.5) / 2 * a r2 = (-b - ((b ** 2) - (4 * a * c))**0.5) / 2 * a

After that, you will have to compute the roots of the equation.

a = (b ** 2) - 4 *(a * c)

Evaluate discriminant

if(b > 0): print("The roots of the equation are ", r1, "and", r2) elif(b == 0): print("The roots are identical ", r1) else:

print("The equation has no roots ")

Note: you must save your program with this extension (name of program.py)

Bravo!!!!

Now let’s move to the phase2. How do you run this program? After you are done in writing the program, you wish to run it isn’t it? That’s what am going to elaborate on. Open command prompt by pressing windows key + r A dashboard will appear. Type in cmd

Locate the area where you saved the program. Use cd to change direction.

phone: +2349034595610 facebook: ayamnelrodinho1@gmail.com email: talk2nelsonjohn2day@yahoo.com whatsapp: +2349034595610

Sign in with your email address to get our latest post.


 
 
 

Comments


bottom of page