Skip to content

Stack operation

Stack operation

Solution

stack = [] Stud = {'Amit': 40, 'Rajeev': 59, 'Nilam': 75, 'Sanyam': 49} def PUSH(Student): for name in Student: if Student[name] > 50: stack.append(Student[name]) print("Pushed:", Student[name]) def POP(): if len(stack) == 0: print("Stack is Empty") else: print("Popped:", stack.pop()) def DISPLAY(): if len(stack) == 0: print("Stack is Empty") else: print("Full Stack (Top to Bottom):") for i in range(len(stack) - 1, -1, -1): print(stack[i]) # Function Calls PUSH(Stud) DISPLAY() POP() DISPLAY()