[Edu-sig] Python First: Free access for educators

kirby urner kirby.urner at gmail.com
Wed Mar 8 16:54:43 CET 2006


Dang, got away from me, anyway, like:

def switch(choice, functions = [cf0, cf1, cf2, cf3])
    if 0<choice<len(functions):
       return functions [ choice ]  # functions is a list of function objects
    else:
       print "Not valid"
       return

variations on that theme, i.e. not a big if, elif, elif, else -- just
use choice as an index into a list of functions.

Kirby


On 3/8/06, kirby urner <kirby.urner at gmail.com> wrote:
> Cool, I'm in.  Checking out your moodle.
>
> Another way people write switch:
>
> def switch(choice):
>      if 0<choice<len(functions):
>


More information about the Edu-sig mailing list