Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers. The function returns the value deleted from the stack.

Answer:

def POP(Arr):

top=len(Arr)-1

if len(Arr)!=0:

deleted_val=Arr[top]

Arr.pop()

else:

print("Stack is Empty")

return deleted_val

 

Slide27.JPG

 

Remove Ads
Teachoo · Class 12 Explore Class 12

Transcript

Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers. The function returns the value deleted from the stack. Answer: def POP(Arr): top=len(Arr)-1 if len(Arr)!=0: deleted_val=Arr[top] Arr.pop() else: print("Stack is Empty") return deleted_val

Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.