[Tutor] Fw: Creating sub-menus?

ALAN GAULD alan.gauld at btinternet.com
Thu Jan 1 11:58:44 CET 2009

Forwarding to the list....
Please use ReplyAll when responding.

On Wed, Dec 31, 2008 at 4:10 AM, Alan Gauld <alan.gauld at btinternet.com> wrote:

"nathan virgil" <sdragon1984 at gmail.com> wrote

Each menu is a function that prints out options, saves a raw_input as the
variable choice, and returns choice. In the main menu, each option leads to
a sub-menu. After choice is defined, however, the sub-menu "tags" the value
of choice.

Yes that can all work.

Then create a loop of while choice !=q, run current_menu, and include a
bunch of statements along the lines of:

if choice == <value that leads to first sub-menu>:
      current_menu = <function name for first sub-menu>

Consider using a dictionary keyed by your combined choice values.
Then the big if/elif chain shrinks to

returnValue = FuncDict[choice](params)

The only challenge with this route is making all the functions
take a single input argument. But that argument can be a tuple :-)

Dictionaries? Tuples? I just figured out functions, so I'm very new. I'm still working on understanding lists. I know what I have probably isn't the best solution for what I'm trying to do, but I'm trying to work with the little that I know. 

This seems like it would work, but for some reason, every time I run the
code, it freezes after I give input from the main menu. Can anybody help? I
can show my source code, but indentation doesn't seem to copy/paste very
well, so it may be a bit hard to read...

Try putting it on the pastebin web site and sending us the URL.
That gives us colour coding of syntax too which helps read it!


It's a simple formula calculator, so the point isn't really the content. I don't have all the formulas coded in yet, but the way I see it, if I can't access the sub-menus that lead to the formulas, then it doesn't do me any good to have the formulas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090101/845adb7d/attachment.htm>

More information about the Tutor mailing list