def back(): turn("left") turn("left") def navigateAroundWall(): if hasBlocked('right'): move() else: turn("right") move() while (True): if (isLightOn()): toggle() break elif (hasBlocked('right') and hasBlocked('forward') and hasBlocked('left')): back() else: navigateAroundWall()