- Code: Select all
`print('''Welcome to:`

+--------------------+

|EQUATION SOLVER V0.2|

+--------------------+

by: Luís Ferreira

''')

#module imports

import time

import math

#defining functions

def continue1choice():

continue1 = input('Do you want to solve more equations? (y/n) ')

if continue1 == 'y':

EquationSolver()

elif continue1 == 'n':

print('Thank you for checking my app!')

time.sleep(3)

elif continue1 != 'y' and continue1 != 'n':

print('You must chose "y" (yes) or "n" (no)!')

continue1choice()

def EquationSolver():

EquationType = input('Equations degree (1st or 2nd): ')

if EquationType == '1st':

def solve1(eq,var='x'):

eq1 = eq.replace("=","-(")+")"

c = eval(eq1,{var:1j})

print(-c.real/c.imag)

eq = input('Type your equation here (use "x" as variable): ')

solve1(eq,var='x')

time.sleep(2)

continue1choice()

elif EquationType == '2nd':

def solve2():

print('Your equation is, in the canonical form: a*x^2 + b*x + c = 0')

a = int(input('Assign a value to "a": '))

b = int(input('Assign a value to "b": '))

c = int(input('Assign a value to "c": '))

delta = b**2 - 4*a*c

if delta < 0:

print('The equation is impossible - it has 0 solutions.')

continue1choice()

elif delta == 0:

x = -b

print('Your equation has 1 solution, which is %r.' % r)

continue1choice()

elif delta > 0:

pass

sqrtDelta = math.sqrt(delta)

x1 = (-b + sqrtDelta)/2*a

x2 = (-b - sqrtDelta)/2*a

print('Your equation has 2 solutions, which are %r and %r.' %(x1, x2))

solve2()

continue1choice()

def MainMenu():

print('- MAIN MENU -')

print('What do you want to do?')

print('''[1] Start solving equations

[2] More info

[3] Quit''')

option1 = input(':: ')

if option1 == '1':

EquationSolver()

elif option1 == '2':

print('''- More info -

This small app, Equation Solver, was totally made by me,

Luís Ferreira, in order to use it for educational purpo-

ses for me (to start working better with Python) and for

others too, as a suplement to their education in Math. I

hope that you comprehend that there maybe many mistakes

with the code, since I'm relativly new to Python and sin-

ce this project is still in a very fresh fase. However,

I don't want to make this like Sympy or other equation

solvers - although I used some useful tips and code avai-

lable on the internet. I hope you enjoy it and let me know

about any mistakes or sugestions.

Thank you for trying it!''')

input('Press [enter] to continue')

print('')

MainMenu()

elif option1 == '3':

print('Thank you for checking my app!')

time.sleep(3)

elif option1 != '1' and option1 != '2' and option1 != '3':

print('You must chose an available option!')

MainMenu()

#proper execution

MainMenu()

Best regards,

Luis Ferreira.