I am new to programming and am trying to calculate the depth of a binary tree in Python . I believe that my error is because depth is a method of the Node class and not a regula
For clarity I would suggest writing your depth method like this:
depth
def depth(self): current_depth = 0 if self.left: current_depth = max(current_depth, self.left.depth()) if self.right: current_depth = max(current_depth, self.right.depth()) return current_depth + 1