Calculate the discriminant value in Python

In this session, we are going to discuss the definition of the Discriminant and how to calculate it’s valued by taking 3 points in Python.

How to calculate the discriminant value in Python?

Discriminant:

The discriminant is that the naming convention that is given to the mathematical expression that seems beneath the root (radical) sign up the quadratic formula.




The formula of  discriminant is given below:

 Discriminant = (b**2) - (4*a*c)
              where a,b and c are three given points.

Now move on to coding or implementation part:

First of all, create a function which takes the three inputs values and calculate the discriminant of points.

#create  a function to calculate the Discriminant value of given points.
def discriminant():
    #Take 3 point's as a input value 
    a = float(input('Please Enter the 1st value point a: '))
    b = float(input('Please Enter the 2nd value point b: '))
    c = float(input('Please Enter the 3rd value point c: '))
    #calculate the Discriminant value.
    Dis = (b**2) - (4*a*c)

Discriminant checking conditions for the possibility of their solutions:

#checking Discriminant conditions and possible solutions.
if Dis > 0:
    print('There are two  Solutions are possible and Discriminant value is:',Dis)
elif Dis == 0:
    print('There are only one Solutions is possible and Discriminant value is:', Dis)
elif Dis < 0:
    print('There are No  Solutions are possible and Discriminant value is:',Dis)

Now combine the whole part of the program:

#python code for finding the arc length of the angle.
#create  a function to calculate the Discriminant value of given points.
def discriminant():
    #Take 3 point's as a input value 
    a = float(input('Please Enter the 1st value point a: '))
    b = float(input('Please Enter the 2nd value point b: '))
    c = float(input('Please Enter the 3rd value point c: '))
    #calculate the Discriminant value.
    Dis = (b**2) - (4*a*c)
    #checking Discriminant conditions and possible solutions.
    if Dis > 0:
        print('There are two  Solutions are possible and Discriminant value is:',Dis)
    elif Dis == 0:
        print('There are only one Solutions is possible and Discriminant value is:', Dis)
    elif Dis < 0:
        print('There are No  Solutions are possible and Discriminant value is:',Dis)

#function call.
discriminant()

Output1:

Please Enter the 1st value point a: 4
Please Enter the 2nd value point b: 8
Please Enter the 3rd value point c: 2
There are two  Solutions are possible and Discriminant value is: 32.0

I hope you have understood the process to calculate the discriminant value in Python.

Also, read:

 


Leave a Reply

Your email address will not be published. Required fields are marked *