Fewpal
0 votes
1.3k views
in Computer by (47.7k points)
closed by

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.

1 Answer

+1 vote
by (50.2k points)
selected by
 
Best answer

Using of any correct code giving the same result is also accepted.

def PUSH(Arr,value): 

s=[]

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

if Arr[x]%5==0: 

s.append(Arr[x]) 

if len(s)==0:

print("Empty Stack") 

else: 

print(s)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...