森栏
虽然官方文档很乐意不提供切换,但我看到了使用词典的解决方案。例如:# define the function blocksdef zero():
print "You typed zero.\n"def sqr():
print "n is a perfect square\n"def even():
print "n is an even number\n"def prime():
print "n is a prime number\n"# map the inputs to the function blocksoptions = {0 : zero,
1 : sqr,
4 : sqr,
9 : sqr,
2 : even,
3 : prime,
5 : prime,
7 : prime,}然后调用等效的开关块:options[num]()如果你严重依赖于跌倒,这就开始分崩离析了。