Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at least one element, otherwise display appropriate error message.

Answer:

def PUSH(Arr):

stack=[]

for i in range(0,len(Arr)):

if Arr[i]%5==0:

stack.append(Arr[i])

if len(stack)==0:

print("Stack is Empty")

else:

print(stack)

 

Slide26.JPG

Remove Ads
Teachoo · Class 12 Explore Class 12

Transcript

Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has at least one element, otherwise display appropriate error message. Answer: def PUSH(Arr): stack=[] for i in range(0,len(Arr)): if Arr[i]%5==0: stack.append(Arr[i]) if len(stack)==0: print("Stack is Empty") else: print(stack)

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.