Answer to Question #349166 in Python for SAIKUMAR

Question #349166
Implement the function find_roots to find the roots of the quadratic equation:= ax2 + bx + c = 0. the function should return a tuple containing roots in any order. If the equation has only one solution. The Equation will always have at least one solution. 

The roots of the quadratic equation can be found with the following formula :

-b = +- square_root b2 - 4ac


for example, find _roots (2, 10, 8) should return (-1, -4) or (-4, -1) as the roots of the equation 2x2 + 10X + 8 are -1 and -4

"\\lnot"

1
Expert's answer
2022-06-08T17:23:56-0400
import math
a = int(input("Enter a: "))
b = int(input("Enter b: "))
c = int(input("Enter c: "))


def find_roots(a, b, c):
    D = b ** 2 - 4 * a * c
    if D > 0:
        x1 = round(((-b + math.sqrt(D)) / (2 * a)), 2)
        x2 = round(((-b - math.sqrt(D)) / (2 * a)), 2)
        print((x1, x2))
    elif D == 0:
        x1 = x2 = -b / 2 * a
        print((x1))
    else:
        print('The equation has no solution')
        
find_roots(a, b, c)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS