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 :: how to make a pause in python 
Python :: pipenv with specific python version 
Python :: plotting two columns of a dataframe in python 
Python :: python test is nan 
Python :: how to slice even index value from a list in python using slice function 
Python :: how to distribute a dataset in train and test using scikit 
Python :: python regex match words 
Python :: imblearn randomoversampler 
Python :: python create list from range 
Python :: pandas create a calculated column 
Python :: python get attributes of class 
Python :: opencv dilate 
Python :: pyautogui press enter 
Python :: hex to binary python3 
Python :: remove specific word from string using python 
Python :: ValueError: `logits` and `labels` must have the same shape, received ((None, 2) vs (None, 1)). 
Python :: python writelines 
Python :: how store list in django session 
Python :: how to create a tuple from csv python 
Python :: numpy count occurrences in array 
Python :: Plot regression line from sklearn 
Python :: pygame how to draw a rectangle 
Python :: _getfullpathname: path should be string, bytes or os.PathLike, not list 
Python :: python zeros to nan 
Python :: how to save the model in python 
Python :: PIL image example 
Python :: list of numbers 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =