I am trying to write a switch case using a dictionary, and calling functions from them all. But the {key,value}
pairs are all being printed:
def addWord():
print "Add word"
def searchWord():
print "Search word"
def displayAll():
print "display all"
#Executing the choice
def switch_choice(choice):
switcher = {
1:addWord(),
2:searchWord(),
3:displayAll()
}.get(choice,"Invalid input")
#MAIN
print "Enter your choice"
print "1.Add new word"
print "2.Search for a word"
print "3.Display all words"
choice=input()
switch_choice(choice)
Output -
Enter your choice
1.Add new word
2.Search for a word
3.Display all words
1
Add word
Search word
display all
Can anyone please let me know the reason.