'''menuwithfunctions.py -- a simple menu-driven program Jeff Ondich, 9 April 2009 This is a version of menu.py that puts most of the code into separate functions. This is a small illustration of how to break a big problem into smaller sub-problems. ''' import random def printMenu(): print 'A. Tell me a joke' print 'B. Sing me a song' print 'C. Give me a random number from 1 to 10' print def tellJoke(): print 'Why is 6 afraid of 7?' print 'Because 7, 8, 9.' def singSong(): print 'Oh Danny boy, the pipes the pipes are calling' print 'From glen to glen, and down the mountainside...' def getRandomInt(): return random.randint(1, 10) printMenu() response = raw_input('Your choice? ') if response == 'A': tellJoke() elif response == 'B': singSong() elif response == 'C': print 'Here you go:', getRandomInt() else: print 'Please choose A, B, or C next time'