Leaf search in forrest II

While Kara is not on a leaf, he attempts to walk straight ahead. When there is a tree in front of him, he walks to its left side and calls the method followTrees. This method makes him walk straight ahead while there is tree to his right. Afterwards, Kara returns to the row with trees and continues his search.

def followTrees():
  while kara.treeRight():
    kara.move()


while not kara.onLeaf():
  if kara.treeFront():
    kara.turnLeft()
    kara.move()
    kara.turnRight()
    kara.move()
    followTrees()
    kara.turnLeft()
    kara.move()
    kara.turnRight()
  else:
    kara.move()
    
kara.removeLeaf()