Write a program to calculate the roots of a quadratic equation.

 


                                                     Write a python program to determine whether a person is eligible to vote.


Write a program to calculate the roots of a quadratic equation.

PROGRAM:

# The general equation of a quadratic equation is ax^2+bx+c=0.

a=int(input("Enter \'a\':"))

b=int(input("Enter \'b\':"))

c=int(input("Enter \'c\':"))

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

if (n==0):

    print("Real and equal roots.")

    print("The roots of a quadratic equation"+str(a)+"x^2"+str(b)+"x"+str(c)+"is",-b/2*a)

elif (n<0):

    print("Imaginary roots")

elif (n>0):

    print("Real and distinct roots.")

    print("The one  root of a quadratic equation"+str(a)+"x^2+"+str(b)+"x+"+str(c)+"is ",(-b+(n**(1/2)))/2*a)

    print("The another root of a quadratic equation"+str(a)+"x^2+"+str(b)+"x+"+str(c)+"is ",(-b-(n**(1/2)))/2*a)

OUTPUT:


No comments:

Post a Comment




Copyright Ⓒ 2022 | Mechpedia | All Right Reserved.