Horje
roots of quadratic equation in python Code Example
roots of quadratic equation in python
#how to find roots in quadratic equation
a=int(input('Enter coefficient of x2 :'))
b=int(input('Enter coefficient of x :'))
c=int(input('Enter the constant :'))
if a==0:
  print("a can't be 0")
else:
  D=b**2-4*a*c
  if D>0:
   print('The roots are real and distinct')
   r1=(-b+D**0.5)/(2*a)
   r2=(-b-D**0.5)/(2*a)
   print("The roots are",r1,"and",r2)
  elif D==0:
   print('The roots are real and equal')
   r=-b/(2*a)
   print('The root is',r)
  else:

   print('The roots are imaginary')
#output:
#real and equal
Enter coefficient of x2 :1
Enter coefficient of x :-4
Enter the constant :4
The roots are real and equal
The root is 2.0
#not real
Enter coefficient of x2 :4
Enter coefficient of x :5
Enter the constant :6
The roots are imaginary
#real and not equal
Enter coefficient of x2 :1
Enter coefficient of x :-5
Enter the constant :6
The roots are real and distinct
The roots are 3.0 and 2.0
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("\n 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')




Python

Related
wait for input python Code Example wait for input python Code Example
make column nullable django Code Example make column nullable django Code Example
scatter plot plotly Code Example scatter plot plotly Code Example
python read url Code Example python read url Code Example
django group by date from datetime field Code Example django group by date from datetime field Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11