# # a program that uses a list but uses exception handling # to deal with unexpected problems # # written e.bonakdarian dec 2009 # ingridients = ['ham', 'pineapple', 'onion'] num_ingridients = len(ingridients) print('You have a choice of %d ingridients, they are:' % num_ingridients) print ingridients print try: prompt = 'Please select an ingridient in the range 1 - %d: ' % num_ingridients number = input(prompt) print('You selected %d which is "%s" - good choice!' % (number, ingridients[number-1])) except NameError: print '\nERROR: You did not specify a valid number.' except IndexError: print '\nERROR: The number you specified (%d) was outside the' % number print ' valid range of 1 - %d.' % (num_ingridients) raw_input('\n to exit')