Peek Top Element of Stack
📖 Scenario: You are managing a stack of books. You want to see which book is currently on the top without removing it.
🎯 Goal: Build a simple stack using a list and write code to peek (look at) the top element of the stack.
📋 What You'll Learn
Create a list called
stack with exact elements 'Math', 'Science', 'History'Create a variable called
top_index to hold the index of the top elementUse
top_index to get the top element from stack and store it in top_elementPrint the value of
top_element💡 Why This Matters
🌍 Real World
Stacks are used in many places like undo features in apps, browser history, and managing tasks in order.
💼 Career
Understanding stacks helps in software development roles where managing data order and temporary storage is needed.
Progress0 / 4 steps