3.4. Discriminant Problem ¶
Ozi wants to help his sister with her math homework, which is about determinig whether a given quadratic equation has real roots or not.
Remember that a given quadratic equation \(ax^2 + bx + c\) has real roots if the discriminant is greater than or equal to 0, where the discriminant is defined as follows:
(3.4.1)¶\[\Delta = b^2 - 4ac\]
.
Write a function called has_real_roots that takes three integers as
the coefficients of the equation and returns True
if this equation
has real roots and False
if not.
Sample I/O:
>>> has_real_roots(1, -4, 4)
True
>>> has_real_roots(1, -2, 4)
False
def has_real_roots(a, b, c):
delta = b**2 - 4*a*c
return delta >= 0