I have a question regarding function-calls using if-statements and recursion. I am a bit confused because python seems to jump into the if statements block even if my function returns "False"
Here is an example:
1 def function_1(#param):
2 if function_2(#param):
3 #do something
4 if x<y:
5 function_1(#different parameters)
6 if x>y:
7 function_1(#different parameters)
My function_2 returns "False" but python continues the code on line 5 for example. Can anyone explain this behavior? Thanks in advance for any answers.
edit: Sorry, forgot the brackets
concrete example:
1 def findExit(field, x, y, step):
2 if(isFieldFree(field, x, y)):
3 field[y][x] = filledMarker
4 findExit(field, x + 1, y, step+1)
5 findExit(field, x - 1, y, step+1)
6 findExit(field, x, y + 1, step+1)
7 findExit(field, x, y - 1, step+1)
8 elif(isFieldEscape(field, x, y)):
9 way.append(copy.deepcopy(field))
10 wayStep.append(step+1)def isFieldFree(field, x, y):if field[y][x] == emptyMarker:return Trueelse:return Falsedef isFieldEscape(field, x, y):if field[y][x] == escapeMarker:return Trueelse:return False
After both functions "isFieldFree" and "isFieldEscape" return False python continues the code in line 5 sometimes in line 6.