# L-21 MCS 260 : a stack
"""
This program uses the stack_of_data.
"""
from ast import literal_eval

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 : ')
        data = literal_eval(item)
        stack_of_data.push(data)
    elif choice == 'r':
        item = stack_of_data.pop()
        print('item popped : %d' % item)
    else:
        print('invalid choice, try again')

def test_input_output():
    """
    Tests input/output operations.
    """
    items = input('give a list : ')
    data = literal_eval(items)
    stack_of_data_io.push_all(data)
    lenstk = stack_of_data.length()
    print('length of stack : %d' % lenstk)
    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 = input(MENU)
    if CHOICE == 's':
        break
    pop_or_push(CHOICE)
    test_input_output()
