This Python program to find the solution of a quadratic equation and discern if it is a complex number, results in the following error:
"message": "IndentationError: unindent does not match any outer indentation level",
IndentationError: unexpected indent
It is an indentation error, but no matter how much I indent everything again, it still gives the same error.
The program is as follows:
from math import sqrt
class Ecuaciones2Grado():
def __init__(self):
self.interfaz()
def calcular(self, A, B, C):
if ((B**2)-4*A*C) < 0:
print("La solución de la ecuación es con números complejos")
else:
int x1, x2
x1 = (-B+sqrt(B**2-(4*A*C)))/(2*A)
x2 = (-B-sqrt(B**2-(4*A*C)))/(2*A)
print("Las soluciones de la ecuación son:", x1, x2)
def interfaz(self):
A = int(input("Ingrese el coeficiente de la variable cuadrática\n"))
B = int(input("Ingrese el coeficiente de la variable lineal\n"))
C = int(input("Ingrese el término independiente\n"))
self.calcular(A, B, C)
Code :
Explanation :
interfaz()
returns a list based on the values entered by the user. The list is saved in the variablevalores
. is calledcalcular()
with the elements of the list.I have changed all the indentation to spaces, and now it works correctly. It is possible that the error
IndentationError: unexpected indent
was due to using spaces in some cases and tabulation in others.Result :
Example 1, with A = 1, B = 10 and C = 1, solution with real numbers:
Example 2, with A = 10, B = 5 and C = 10, solution with complex numbers: