0
a = float(input("A = "))
b = float(input("B = "))
c = float(input("C = "))
delta = float(b**2-4*a*c)
raiz = (delta ** 0.5)
if raiz is float or int:
raiz = float(delta ** 0.5)
x1 = float((-b + raiz) / (a * 2))
x2 = float((-b - raiz) / (a * 2))
if x1 == x2:
print("O resultado é %f" % x1)
else:
resultado = (x1, x2)
print("O resultado é ou %f ou %f" % resultado)
else:
print("Não há raízes reais. Delta é %s" %delta)
The classical formula avoids arriving at a complex number. Ask instead if the delta is negative, do not attempt to calculate the negative root
– Jefferson Quesado
Besides what Jefferson said, to complement,
if raiz is float or int
is wrong, the correct to check the type of the variable would beif isinstance(raiz, (float, int)):
– nosklo
Thanks guys, it worked!
– Lucas Batista