You got a solution from mata, but I suggest you also look at your code and understand what it does:
while self.right != None: self = self.right path = path +1
What will it be? he will find the right child, then his right child, etc. Thus, it checks only one path of the "rightmost" sheet.
This does the same for the left:
while self.left != None: self = self.left path = path +1
The idea in recursion is that for each subtask, you solve it using the same recipe for all the other subtasks. Therefore, if you apply your algorithm only to a subtree or to a sheet, it will still work.
In addition, the recursive definition invokes itself (although you can implement this with a loop, but it is out of scope).
Recall the definition:
Recursion: see definition of recursion.
;)
source share