py: Fix approach() and rapproach() haven't returned correct value

This bug is introduced by a mistake in porting ternary conditional
operators from JavaScript to Python style.