Hernandez Lab Act 6
Hernandez Lab Act 6
CPE - 301
Objective:
• To understand the basic operations of a stack (push, pop, peek) using Python lists to represent the stack.
Instructions:
1. Create a class Stack that uses a Python list to store the elements.
o pop() – Remove and return the top item from the stack. Ensure the stack is not empty before
popping.
o peek() – Return the top item from the stack without removing it.
Task:
1. Push the elements [5, 10, 15, 20] onto the stack.