Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

roots of quadratic equation in python

#root of quadratic equation
a=int(input('Enter coefficient of x2 :'))
b=int(input('Enter coefficient of x :'))
c=int(input('Enter the constant :'))
import math as m
if a==0:
    print(a,'value of a can not be zero')
    print("
 aborting!!!!!!")
else:
    delta=b**2- 4*a*c
    if delta<0:
        root1=((-b + m.sqrt(delta))/(2*a))
        root2=((-b - m.sqrt(delta))/(2*a))
        print('roots are real and distinct')
        print('roots are',root1,'and',root2)
    elif delta==0:
        root=((-b+ m.sqrt(delta))/(2*a))
        print('roots are real and equal')
        print('root is',root,'each')
    else:
        print('roots are imaginary')
 
PREVIOUS NEXT
Tagged: #roots #quadratic #equation #python
ADD COMMENT
Topic
Name
3+8 =