In: Computer Science
Menu Writing - Python - Please include #Comments in each line for explanation
(a) A common task while writing any software is to display a menu and ask the user for a choice. One such example is the menu on your cellphone. It has messaging, contacts, games, settings, media, and web (and possibly others) as options. Write a function called display menu that displays the menu to the user and allows the user to make a choice (using input).
(b) Write a function that takes the choice of the user and makes calls to the other functions that correspond to the operation to be performed. (Give meaningful
names to the functions. You don’t have to write the other function definitions.)
def display_menu():
print "Choose one of the following:"
print "1. messaging"
print "2. contacts"
print "3. games"
print "4. settings"
print "5. media"
print "6. web"
print "0. exit"
print "input any of number from 1 to 6"
def choose(choice):
if choice == 1:
messaging()
elif choice == 2:
contacts()
elif choice == 3:
games()
elif choice == 4:
settings()
elif choice == 5:
media()
elif choice == 6:
web()
def main():
while True:
display_menu()
choice = int(raw_input())
while choice < 0 or choice >
6:
print "invalid
input, try again"
choice =
int(raw_input())
if choice == 0:
return
choice(choice)
if __name__ == "__main__":
main()