Question: recursion and scope

adina_levin at mindspring.com adina_levin at mindspring.com
Mon Mar 25 13:47:30 EST 2002


Hello, Pythonistas.

I am attempting to teach myself some basic computer programming concepts
using Python.

I'm currently extending the recursive binary tree program in Programming
Python to traverse the tree and count its depth. The program successfully
traverses the tree and counts the number of nodes.

So far, though I haven't figured out how to calculate the "maximum depth" of
the tree without declaring "maxdepth" as a global variable.

If maxdepth is declared as a local variable within the recursive method, it
gets re-set for each subtree.

What am I missing?

Many thanks,

- Adina















More information about the Python-list mailing list