1.

Write the pop operation of stack containing numbers using class.

Answer»

class stack:

s=[]

def push(self):

a=input(“Enter number :”)

stack.s.append(a)

def pop(self):

if (a.s==[]):

print “Stack Empty”

else:

print “Deleted element is : ”,a.s.pop()

def display(self):

l=len(stack.s) print “STACK CONTENTS”

for i in range(l-1,-1,-1):

print stack.s[i]

a=stack()

n= input(“Enter count of numbers”)

for i in range (n):

a.push()

a.pop()

a. display ()



Discussion

No Comment Found