a = """ 1. PUSH 2. POP 3. TOP 4. EMPTY 5. Max""" choice = "Yes" while choice: print(a) b = int(input('Enter your choice: ')) if b == 1: c = int(input('Enter the element you want to push: ')) stack.Push(c) print(stack.display()) elif b == 2: if stack.Empty(): print('Stack is empty') else: print('Popped element {} from the stack {}'.format( stack.Pop(), stack.display())) elif b == 3: print("The top element in the stack is {}", stack.Top()) elif b == 4: if not stack.Empty(): print('Stack is not empty') else:
from Stack import Stack s = Stack(); s.push(1); s.push(2); s.push(3); s.push(4); s.display()
from Stack import Stack def printInstructions(): print('Command List') print('1. Push') print('2. Pop') print('3. Peek') print('4. Display') print('5. Exit') stack = Stack() while True: choice = int(input('Enter your command: [0 for Commands List]')) if choice == 0: printInstructions() elif choice == 1: item = int(input('Enter item: ')) stack.push(item) elif choice == 2: stack.pop() elif choice == 3: print(f'Item on top is {stack.peek()}') elif choice == 4: stack.display() elif choice == 5: break