Skip to content

Instantly share code, notes, and snippets.

Created August 12, 2018 02:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save SeanSyue/76fa80d96f91af6c12a28b2aa65d6dff to your computer and use it in GitHub Desktop.
Implement switch functionality in Python.
def switch_(index_):
def 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")
options = {0: zero,
1: sqr,
4: sqr,
9: sqr,
2: even,
3: prime,
5: prime,
7: prime,
return options[index_]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment