Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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
Comment

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')
Comment

PREVIOUS NEXT
Code Example
Python :: how to tell if member is a bot discord.py 
Python :: find the sum of all the multiples of 3 or 5 below 1000 python 
Python :: zip django template 
Python ::  
Python :: pipenv with specific python version 
Python :: plotting two columns of a dataframe in python 
Python :: python test is nan 
Python :: python snakes 
Python :: true positive true negative manually 
Python :: python input function 
Python ::  
Python :: replace value pandas df 
Python :: change colorbar size and place python 
Python :: construct contingency table from pandas 
Python :: delete rows with value in column pandas 
Python :: exeption python syntax 
Python :: find common values in different dataframes pandas 
Python :: python numphy how to use fractions 
Python :: get all file in folder python 
Python :: manipulate ip address in python 
Python :: __call__ python 
Python :: python keyboardinterrupt 
Python :: template string python 
Python :: install imgkit py 
Python :: make entry bigger in tkinter python 
Python :: Adjusting Subplot Margins in Matplotlib 
Python :: enum python 
Python :: python password hashing 
Python :: seaborn bar plot 
Python :: input and ouput array in python 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =