KnowledgeBoat Logo
|

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