CBSE Class 12 Computer Science
Question 37 of 63
Data Structures in Python — Question 11
Back to all questions 11
Question Give the necessary declaration of a list implemented Stack containing float type numbers. Also, write a user-defined function to pop a number from this Stack.
# Declaration for list implemented stack
Stack = list()
#Function body to pop a number from the stack
def pop_element(Stack):
if not Stack:
print("Stack is empty")
else:
Num = Stack.pop()
print("Value deleted from stack is", Num)
Stack = [1.5, 2.7, 3.2, 4.9]
print("Initial Stack:", Stack)
pop_element(Stack)
print("Stack after pop operation:", Stack)Initial Stack: [1.5, 2.7, 3.2, 4.9]
Value deleted from stack is 4.9
Stack after pop operation: [1.5, 2.7, 3.2]