Python: So I am working on a program (which is a class assignment) that will take an expression such as 3/4/5 or 32432/23423/2354325 or 3425*343/254235 or 43252+34254-2435, etc(for all operators from +,-,/,*). and will solve the expression.
I CANT USE EVAL!!
I cant use higher level codes, I am limited to, at most, using string manipulators from the below website to split the string.
http://docs.python.org/2/library/stdtypes.html#typesseq
My method is to look at the expression the user enters and then use a find function to find the OPERATORS, and then use these operators and a slicing function (eg. s[0:x]). What I have is below and unfortunately it isnt working: *note that the print statements are in there for debugging purposes only. EDIT: why is x not defined when I run the program and enter an expression?
z= (input("expression:")).strip()
def finding(z):
if "/" in z:
x=z.find("/")
print("hi1")
elif "*" in z:
x=z.find("*")
print("hi2")
elif "+" in z:
x=z.find("+")
print("hi3")
elif "-" in z:
x=z.find("-")
print("hi4")
else:
print("error, not math expression")
return x
def Parsing(z,x):
x= finding(z)
qw=z.s[0:x]
print (qw)
# take the x-value from function finding(z) and use it to split
finding(z)
Parsing(z,x)