def solve_eq(self, coefs): if (self.check_infinite(coefs)): Printer.infinite_solution() if (not self.is_degree_valid(coefs)): Printer.cant_resolve(coefs) if (not self.are_coefs_valid(coefs)): Printer.impossible(coefs[0]) Printer.reduce_form(coefs.copy()) if (not coefs.get(2) or coefs[2] == 0): sol = -coefs[0] / coefs[1] print("The solution is :\n{}".format(self.sol_to_str(sol, coefs))) exit() delta = (coefs[1] * coefs[1]) - (4 * coefs[2] * coefs[0]) if (delta < 0): print("The discriminant is stricly negative, there is no solution") elif (delta == 0): sol = (-coefs[1]) / (2 * coefs[2]) print("The discriminant is equal to 0," + " the solution is :\n{}".format( self.sol_to_str(sol, coefs, delta))) else: sol_1 = (-coefs[1] - (delta**0.5)) / (2 * coefs[2]) sol_2 = (-coefs[1] + (delta**0.5)) / (2 * coefs[2]) print("The discriminant is stricly positive, the two solutions " + "are :\n{}\n{}".format( self.sol_to_str(sol_1, coefs.copy(), delta, -1), self.sol_to_str(sol_2, coefs, delta)))