हिंदी

Write the pop operation of stack containing numbers using class.

Advertisements
Advertisements

प्रश्न

Write the pop operation of stack containing numbers using class.

कोड लेखन
Advertisements

उत्तर

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
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 6: Stacks & Queues in list - EXERCISE [पृष्ठ १२३]

APPEARS IN

सीबीएसई Computer Science with Python [English] Class 12
अध्याय 6 Stacks & Queues in list
EXERCISE | Q 13. | पृष्ठ १२३
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×