Computer Science
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.
Python
Python Stack
2 Likes
Answer
# 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)
Output
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]
Answered By
3 Likes
Related Questions
How does FIFO describe queue ?
Write a menu driven python program using queue, to implement movement of shuttlecock in it's box.
A linear Stack called Directory contains the following information as contacts:
— Pin code of city
— Name of cityWrite add(Directory) and delete(Directory) methods in Python to add and remove contacts using append() and pop() operations in Stack.
Write add(Books) and delete(Books) methods in Python to add Books and Remove Books considering them to act as append() and pop() operations in Stack.