Most tree questions are solved bottom-up: each node asks its children, combines the two answers it gets and hands its own answer up. For depth the combining is "take the larger and add one"; for the number of nodes it is "add the two and add one".
def depth(node):if node is None:return 0return 1 + max(depth(node.left), depth(node.right))
Sometimes you ask a question about the node itself: is this a leaf? A leaf is a node whose children are both None. Counting leaves there are three cases: an empty tree (0), a leaf (1), an inner node (the two subtrees added; itself not counted).