Feb-09-2020, 04:06 PM
Hi, my homework is to solve quadratic equations and compute complex solutions(the solutions to the quadratic equations are not real numbers). Furthermore, we want to limit ourselves to only 2 decimal places of precision. As such, i am tasked to use the function round(value, dp).
My task is to write two functions solve_qe_small(a, b, c) and solve_qe_large(a, b, c).
however, my following code presented a type error: "type complex doesn't define __round__ method"
I'm not sure how I can compute both complex numbers and at the same time round off the answers to 2 decimal places.
My task is to write two functions solve_qe_small(a, b, c) and solve_qe_large(a, b, c).
however, my following code presented a type error: "type complex doesn't define __round__ method"
I'm not sure how I can compute both complex numbers and at the same time round off the answers to 2 decimal places.
from math import * from cmath import * def solve_qe_small(a, b, c): d = (b**2) - (4*a*c) x1 = (-b - sqrt(d))/(2*a) answer1 = str(round(x1,2)) return answer1 def solve_qe_large(a, b, c): d = (b**2) - (4*a*c) x2 = (-b + sqrt(d))/(2*a) answer2 = str(round(x2, 2)) return answer2 print(solve_qe_small(1, 1, 8)) print(solve_qe_large(1, 1, 8))