How to make A Quadratic Equation Solver | Roboindian | DIY | Python coding

  Quadratic Solver


What are Quadratic equation?

- Quadratic equations are Polynomials in form of ax^2 + bx + c, where a ≠ 0.
- Quadratic equations have only two solutions.

How to Solve a Quadratic Equation?

We can solve a quadratic equation using Quadratic formula derived by Sridharacharya (C.E. 1025)




To make a python program which uses this equation 

  1. Input

    First we have to take the values of coefficient of x that are a, b and c
  2. Compute
    We have to take that data and put in the equation step wise

Now we have a condition here, 
There are several types of roots Depending upon their nature 

If Discriminant or ( b^2 - 4 a c ) = 0 
    then the roots are real and equal 

If Discriminant ≥ 0 
    then the roots are distinct and real 

If discriminant is < 0
    then the roots are not real and cannot be determined by the formula 
     in this case we denote them using "i"

Code:
import math

stra = input("Enter value of a: ");
strb = input("Enter value of b: ");
strc = input("Enter value of c: ");
a = int(stra)
b = int(strb)
c = int(strc)

d = (b**2) - (4*a*c)
print("discriminant is ", d)

if d > 0:
print(" type: real and different roots ")
print((-b + math.sqrt(d)) / (2 * a))
print((-b - math.sqrt(d)) / (2 * a))
elif d == 0:
print(" type: real and same roots")
print(-b / (2 * a))
else:
print("type: Complex Roots")
Library used- Math (stock) 

For queries about code and anything about quadratic equation feel free to upload one at the contact form or comment 

THANKS 






 

0 Comments

Newest