181k views
3 votes
Define the function quadratic_formula with two arguments. The function should use the quadratic formula, only the + version where the first argument is the a value and the second argument is the b value. The c = -2 for the final value.

a) quadratic_formula(a, b)
b) quadratic_formula(b, a)
c) quadratic_formula(c, a)
d) quadratic_formula(b, c)

User Joyell
by
8.1k points

1 Answer

5 votes

Final answer:

A function 'quadratic_formula' calculates the positive root of the quadratic equation using the a and b values of the equation and fixed c value of -2. Utilizing the quadratic formula, the function returns the result of the equation (-b + √(b² - 4ac)) / (2a).

Step-by-step explanation:

To define a function named quadratic_formula that calculates the positive root of a quadratic equation using the values of a and b, with c fixed at -2, you can write the following Python function:

def quadratic_formula(a, b):
discriminant = b**2 - 4*a*(-2)
root = (-b + discriminant**0.5) / (2*a)
return root

The quadratic formula is -b ± √(b² - 4ac) divided by 2a. When you call this function with two arguments, it will substitute the values for a and b into the formula and use -2 for c. For example, calling quadratic_formula(1, 10) will calculate the positive root for the quadratic equation x² + 10x - 2 = 0.

User Kienz
by
7.2k points