import math
def solve_quadratic(a, b, c):
# Calculate the discriminant
discriminant = b**2 - 4*a*c
if discriminant < 0:
return "No real roots"
elif discriminant == 0:
# One real root
root = -b / (2*a)
return (root,)
else:
# Two real roots
root1 = (-b + math.sqrt(discriminant)) / (2*a)
root2 = (-b - math.sqrt(discriminant)) / (2*a)
return (root1, root2)
# Coefficients for the equation x^2 - 5x + 6 = 0
a = 1
b = -5
c = 6
# Solve the equation
roots = solve_quadratic(a, b, c)
print(f"The roots of the equation {a}x^2 + ({b})x + {c} = 0 are: {roots}")
No comments:
Post a Comment