Write a function in Python PUSH(Art), 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.
Answers
Answered by
4
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
Answered by
2
To 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:
Explanation:
To write function where Arr is a list of numbers-
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)
Similar questions