As others said, you should call sqrt()
only with proper values.
So better do
...
#Check discriminant
discrim = float((bval**2)-(4*aval*cval))
if float(discrim >= 0):
# now it is ok to calculate the roots...
root1 = - bval + math.sqrt(discrim)
root2 = - bval - math.sqrt(discrim)
if float(discrim > 0):
print ("Roots at:", root1, root2)
else:
print ("Only one real root:", root1, root2)
else:
print ("No real roots.")
This way we are sure we are allowed to call sqrt
.
0
solved Keep getting math domain error [closed]