Kara walks around the trees in an endless loop. In each step, he considers the sensors "tree front?" and "tree right?" to determine the appropriate action.

while 1:
  if kara.treeFront() and kara.treeRight():
    kara.turnLeft()
  elif not kara.treeFront():
    if kara.treeRight():
      kara.move()
    else:
      kara.turnRight()
      kara.move()