class StudentMarksStack:
def __init__(self):
self.marks_stack = []
def push(self, mark):
self.marks_stack.append(mark)
print(f"Mark {mark} pushed onto the stack.")
def pop(self):
if not self.is_empty():
popped_mark = self.marks_stack.pop()
print(f"Mark {popped_mark} popped from the stack.")
return popped_mark
else:
print("Stack is empty. Cannot pop.")
def is_empty(self):
return len(self.marks_stack) == 0
def display_stack(self):
if not self.is_empty():
print("Student Marks Stack:", self.marks_stack)
else:
print("Student Marks Stack is empty.")
# Example Usage
if __name__ == "__main__":
# Create an instance of the StudentMarksStack
marks_stack_instance = StudentMarksStack()
# Push some marks onto the stack
marks_stack_instance.push(85)
marks_stack_instance.push(92)
marks_stack_instance.push(78)
# Display the current stack
marks_stack_instance.display_stack()
# Pop a mark from the stack
popped_mark = marks_stack_instance.pop()
# Display the updated stack
marks_stack_instance.display_stack()
This program defines a StudentMarksStack class with methods for pushing, popping, checking if the stack is empty, and displaying the current stack. The example usage section demonstrates how to create an instance of the stack, push marks onto it, pop a mark, and display the stack. You can customize and extend this program based on your specific requirements.