You are on page 1of 4

SSCE

PRACTICAL EXAMINATION

COMPUTER SCIENCE(083)

Roll number: 17639834

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)

# Predefined list of numbers


arr = [10, 25, 30, 15, 40, 8, 5]

# Stack implemented using a list


stack = []

while True:
print("\nMenu:")
print("1. PUSH")
print("2. POP")
print("3. Display Stack")
print("4. Quit")

choice = input("Enter your choice (1/2/3/4): ")

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-

You might also like