Professional Documents
Culture Documents
SSCE
SSCE
PRACTICAL EXAMINATION
COMPUTER SCIENCE(083)
CODE-
def PUSH(arr):
for num in arr:
if num % 5 == 0:
stack.append(num)
def POP(arr):
if len(arr)==0:
print("Underflow: Stack is empty")
return None
else:
return arr.pop()
def display_stack(arr):
if len(arr)==0:
print("Error: Stack is empty")
else:
print("Stack:", arr)
while True:
print("\nMenu:")
print("1. PUSH")
print("2. POP")
print("3. Display Stack")
print("4. Quit")
if choice == '1':
PUSH(arr)
print("Numbers divisible by 5 pushed onto the stack.")
elif choice == '2':
deleted_value = POP(stack)
if deleted_value is not None:
print("Deleted value from the stack:", deleted_value)
elif choice == '3':
display_stack(stack)
elif choice == '4':
print("Exiting the program. Goodbye!")
break
else:
print("Invalid choice. Please enter a valid option.")
OUTPUT-