Statement. The roots of a quadratic equation ax² + bx + c = 0 can be determined with the quadratic formula, -b ± √b² - 4ac| 2a X1 X2 =
Develop an algorithm that does the following: Step 1: Prompts the user for the coefficients, a, b, and c. Step 2: Implements the quadratic formula, guarding against all eventualities (for example, avoiding division by zero and allowing for complex roots). Step 3: Displays the solution, that is, the values for x. Step 4: Allows the user the option to return to step 1 and repeat the process.
import numpy as np a eval(input("Please input a: ")) beval(input ("Please input b: ")) ceval (input ("Please input c:")) I=0 rl=0 r2 = 0 d b**2- 4*a*c if a == 0: if b == 0: print("There is no solution to this equation!") elif b 10: r = -b/c print("The solution r \-", r) elif a 10: if d >= 0: L print("The solutions rl and r2 are:", r1, "and", r2, ", respectively.") elif d < 0: print("The equation does not have real solutions.") rl=(-b+np.sqrt(d))/(2*a) r2=(-b-np.sqrt(d))/(2*a)
Problem Problem Statement. The roots of a quadratic equation ax² + bx + c = 0 can be determined with the quadratic formula, -b ±
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am