I've been working on an Equation Solver. Until now, it has worked well, although it had some bugs a crashes that I fixed, some times with help from some members of this forum, since I'm relatively new to Python and this is my first true project. Btw, I already created a page on the Completed scripts section, since the script is almost fully functional (http://python-forum.org/viewtopic.php?f=11&t=4253).

Now, the real problem is that, when solving 2nd degree equations, you may type the value you wish to assign to "a", "b" and "c". However, if you don't type a number in, let's say, "a", it'll give you an error and let you start doing more equations. In this menu, you may only chose 1st or 2nd, but if you type anything besides that, it'll pass and ask you for the next value. I know I'm not explaining very well, so I'll just leave you with my results and the full code to let you test it.

bug:

- Code: Select all
`Welcome to:`

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

|EQUATION SOLVER V0.3|

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

by: Luís Ferreira

- MAIN MENU -

What do you want to do?

[1] Start solving equations

[2] More info

[3] Quit

:: 1

Equations degree (1st or 2nd): 2nd

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

Assign a value to "a": asd

You must type only numbers and math symbols!

Equations degree (1st or 2nd): 2nd

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

Assign a value to "a": asd

You must type only numbers and math symbols!

Equations degree (1st or 2nd): sad

Assign a value to "b":

full code:

- Code: Select all
`import math`

import time

print('''Welcome to:

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

|EQUATION SOLVER V0.3|

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

by: Luís Ferreira

''')

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!')

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':

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

try:

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

end = eval(eq1,{'x':1j})

pass

except SyntaxError:

print('You must write a vallid equation!')

continue1choice()

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

end = eval(eq1,{'x':1j})

print(-end.real/end.imag)

continue1choice()

elif EquationType == '2nd':

solve2()

continue1choice()

def solve2():

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

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

try:

int(a)

pass

except ValueError:

print('You must type only numbers and math symbols!')

EquationSolver()

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

try:

int(b)

pass

except ValueError:

print('You must type only numbers and math symbols!')

EquationSolver()

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

try:

int(c)

pass

except ValueError:

print('You must type only numbers and math symbols!')

EquationSolver()

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

if delta < 0:

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

continue1choice()

elif a == 0 and b == 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))

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()

MainMenu()

Anyway, is there any advice you can give to me for solving this? Any idea?

Thanks in advance!

Best regards,

Luis Ferreira.