Quote:
In my program, if I delete the return-1 statement I get the right answer but otherwise it keeps returning -1. Why does it keep doing so?
Because with this code you get -1 if first letter is not an operator.
Try
def findNextOpr(txt):
if len(txt)<=0 or not isinstance(txt,str):
print("type error: findNextOpr")
return "type error: findNextOpr"
op=['+','-','*','/']
for i in range(len(txt)):
if txt[i] in op:
return(i)
else:
return(-1)
print(findNextOpr("1+2+3"))