Code is for Python 3.3 Quadratic Formula Define a function quadsolve(a, b, c) wh
ID: 3578767 • Letter: C
Question
Code is for Python 3.3
Quadratic Formula Define a function quadsolve(a, b, c) which returns the two values that are the two solutions for x in the quadratic equation ax^2 2 + bx + c = 0: x = (-b plusminus squareroot b^2 - 4ac/2a Example Use from Python (the order of the returned results does not matter!) quadsolve(1, 2, 3) ==> ((-1+1.4142135623730951j), (-1-1.4142135623730951j)) quadsolve(l, -3, 2) ==> ((2+0j), (1-0j)) import cmath def quadsolve(a, b, c): " " " returns two solutions of the quadratic equation a*x**2+b*x+c==0 as given by the quadratic formula. The order of the results is arbitrary " " "Explanation / Answer
import cmath
def quadsolve(a,b,c):
det = cmath.sqrt(b*b-4*a*c)
kk=(-b+det)*1.0/(2*a)
kl=(b+det)*1.0/(2*a)
return (kk,kl)
print(quadsolve(1,2,3))
print(quadsolve(1,-3,2))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.