हिंदी

Write a program that has a user-defined function to accept the coefficients of a quadratic equation in variables and calculate its determinant. For example: if the coefficients are stored in the - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

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

संक्षेप में उत्तर
Advertisements

उत्तर

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 a value of 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.
shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Functions - Exercise [पृष्ठ १७२]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 11
अध्याय 7 Functions
Exercise | Q 3. | पृष्ठ १७२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×