English

Write the pop operation of stack containing numbers using class.

Advertisements
Advertisements

Question

Write the pop operation of stack containing numbers using class.

Code Writing
Advertisements

Solution

class NumberStack:
    def __init__(self):
        self.stack = []

    def pop(self):
        if not self.stack:
            print("Stack Empty")
            return None
        return self.stack.pop()  # Remove the top number


numbers = NumberStack()
numbers.stack.extend([10, 20, 30])
print(numbers.pop())
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Stacks & Queues in list - EXERCISE [Page 123]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 6 Stacks & Queues in list
EXERCISE | Q 13. | Page 123
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×