def equation_to_zero(equation): try: lhs, rhs = map(lambda expr: variables.simplify(tokenizer.gen_tokens(expr)), equation.split('=')) except: raise SyntaxError('This isn\'t an equation!') return lhs - rhs
except: raise SyntaxError('This isn\'t an equation!') return lhs - rhs def sign(n): return '+' if n >= 0 else '-' def f2s(f): return '{:.15g}'.format(f) equation = input('Welcome to the Polynomial Solver!\nPlease enter your polynomial below, using x to represent the roots.\n\n') expression_count = equation.count('=') if expression_count == 0: print(variables.simplify(tokenizer.gen_tokens(equation))) elif expression_count == 1: coeffs = equation_to_zero(equation) quadratic = set(coeffs.keys()) <= {0, 1, 2} if set(coeffs.keys()) <= {0}: print(coeffs[0]) elif quadratic: options = ['Solve with Quadratic Formula','Solve by Completing the Square','Find the Discriminant','Rewrite in Standard Form'] print('\nChoose the problem type:') for i, option in enumerate(options): print('{}) {}'.format(i + 1, option)) while True: option = input('>> ')