Ron Stephens wrote: > >... > > So, now I consider procedural menu program using raw_input. Still, how > do I go to the appropriate sub-program when the user chooses one? With > goto's this would be trivial. Now, I consider a nested set of "if " > statements that determines which number was chosen, but still how do I > "jump" to the correct sub-program??? Even if I define the subprograms as > functions even, how do I jump to them??? Calling a function is the same as jumping to it. Now there are all kinds of swank,y k-rad ways to solve your problem more efficiently or compactly then what I describe below, but I'm trying to keep it simple so you can learn at your own pace. def do_abc(): "does some stuff" #... def do_def(): "does some stuff" #... def do_ghi(): "does some stuff" #... while 1: command = raw_input("> ") if command == "abc": do_abc() elif command == "def": do_def() elif command == "ghi": do_ghi() elif command == "quit": break else: print "Unknown command" -- Take a recipe. Leave a recipe. Python Cookbook! http://www.ActiveState.com/pythoncookbook
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4