Check if Stack is Empty or Full
📖 Scenario: Imagine you have a stack of books on a shelf. You want to check if the shelf is empty or if it is full and cannot hold more books.
🎯 Goal: You will create a simple stack using a list, set a maximum size, write functions to check if the stack is empty or full, and then print the results.
📋 What You'll Learn
Create a list called
stack with these exact elements: ['book1', 'book2', 'book3']Create a variable called
max_size and set it to 5Write a function called
is_empty that returns True if stack is empty, otherwise FalseWrite a function called
is_full that returns True if the length of stack is equal to max_size, otherwise FalsePrint the result of
is_empty() and is_full() exactly as shown💡 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 stack operations is important for software development, especially in areas like memory management and algorithm design.
Progress0 / 4 steps