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
The error is coming from this line:
return max(depth(self.left), depth(self.right)) + 1
You're using depth as a function and trying to apply it to the left and right nodes. Because the left and right nodes are also nodes, they have the depth method.
You should be calling the depth method like this:
return max(self.left.depth(), self.right.depth()) + 1
The self parameter is implicitly passed to the depth method, but using it with the dot operator tells Python that this method belongs to a Node instance, and it is not some other function not bound to an object.