Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
1.2k views
in Computer by (15 points)
Create a python program to create a stack of student’s marks.        

Write function PUSH to add marks in to the stack and

Write function POP to remove the marks from stack and display the same.

Please log in or register to answer this question.

1 Answer

0 votes
by (48.6k points)
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.

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...