wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Write a program that has a user defined function to accept the coefficients of a quadratic equation in variables and calculates its determinant. For example : if the coefficients are stored in the variables a,b,c then calculate determinant as b2 - 4ac. Write the appropriate condition to check determinants on positive, zero and negative and output appropriate result.

Open in App
Solution

A discriminant can be positive, zero, or negative, and this determines the number of solutions to the given quadratic equation.
  • A positive discriminant indicates that the quadratic equation has two distinct real number solutions.
  • A discriminant with value zero indicates that the quadratic equation has a repeated real number solution.
  • A negative discriminant indicates that neither of the solutions of the quadratic equation is a real number.

Program:
#defining the function which will calculate the discriminant
def discriminant(a, b, c):
d = b**2 - 4 * a * c
return d

#asking the user to provide values of a, b, and c
print("For a quadratic equation in the form of ax^2 + bx + c = 0")
a = int(input("Enter the value of a: "))
b = int(input("Enter the value of b: "))
c = int(input("Enter the value of c: "))

#Calling the function to get the discriminant
det = discriminant(a,b,c)

#Printing the result based on the discriminant value
if (det > 0):
print("The quadratic equation has two real roots.")
elif (det == 0):
print("The quadratic equation has one real root.")
else:
print("The quadratic equation doesn't have any real root.")


OUTPUT:
For a quadratic equation in the form of ax^2 + bx + c = 0
Enter the value of a: 2
Enter the value of b: 6
Enter the value of c: 3
The quadratic equation has two real roots.

flag
Suggest Corrections
thumbs-up
2
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Nature of Roots
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon