I'm trying to make a calculation engine in Python
. For example, I have a program named engine.py
, which takes an equation and returns the roots. I wanted to write another program named interface.py
, which would just take the equation and tell the engine to calculate and take the value returned. Can you do that?
engine.py
x = str(input())
x = x.replace("-","+-")
Eq = list(x.split("+"))
b = 0
c = 0
if "" in Eq: Eq.remove("")
for i in range(0,len(Eq)):
if (Eq[i] == "x²"):
a = 1
elif (Eq[i] == "-x²"):
a = -1
elif "x²" in Eq[i]:
aux = Eq[i]
a = int(aux.replace("x²",""))
elif (Eq[i] == "x"):
b = 1
elif (Eq[i] == "-x"):
b = -1
elif "x" in Eq[i]:
aux = Eq[i]
b = int(aux.replace("x",""))
else:
c = int(Eq[i])
delta = (b * b) - 4 * a * c
print("Delta:",delta)
if delta<0:
print('Essa equacao nao tem raiz real')
elif delta==0:
x1 = (-b)/(2*a)
print('Raiz:',x1)
else:
from math import sqrt
x1 = (-b+sqrt(delta))/(2*a)
x2 = (-b-sqrt(delta))/(2*a)
print('Raizes:')
print("x':",x1)
print("x'':",x2)
Interface.py
x = input()
y = manda_para_engine(x)
print(x)
something like this