1.

Write the pop operation of stack containing names using class.

Answer»

class stack:

s=[]

def push (self):

a=raw_input(“Enter any name :”)

stack.s.append(a)

def pop(self):

if (a.s==D):

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 no. of names”)

for i in range(n):

a.push()

a.pop()

a.display()



Discussion

No Comment Found