# MCS 260 L-21 Mon 1 Mar 2010 : a stack # # this program uses a stack_of_data import stack_of_data import stack_of_data_io def pop_or_push(choice): "calls pop and push functions" if choice == 'a': item = input('Give an item : ') stack_of_data.push(item) elif choice == 'r': item = stack_of_data.pop() print 'item popped : %d' % item else: print 'invalid choice, try again' def test_input_output(): "test input/output operations" K = input('give a list : ') stack_of_data_io.input(K) L = stack_of_data.length() print 'length of stack : %d' % L print 'printing top element' stack_of_data_io.show_top() print 'printing the stack' stack_of_data_io.show_all() while True: menu = 'add, remove, or stop? (a/r/s) ' choice = raw_input(menu) if choice == 's': break pop_or_push(choice) test_input_output()