Program No 17 Stack Operation
Program No 17 Stack Operation
Problem Definition:
Write an interactive Python program using the functions DoPush(Customer),
DoPop(Customer) and DoShow(Customer) to push,pop and display the
Customer details like Customer ID, Name, Phone no from the Stack of
Customers.
AIM:
To write an interactive Python program using the functions DoPush(Customer),
DoPop(Customer) and DoShow(Customer) to push,pop and display the Customer
details from the Stack of Customers.
Program:
def isempty(stk):
if stk==[]:
return True
else:
return False
def dopush(stk,li):
stk.append(li)
top=len(stk)-1
print("Values Inserted")
def dopop(stk):
if isempty(stk):
return "stack is empty"
else:
l1=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return l1
def doshow(stk):
if isempty(stk):
print("Stack is empty")
else:
top=len(stk)-1
for a in range(top,-1,-1):
print(stk[a])
stk=[]
top=None
while True:
print("1. Insert Customer Details")
print("2. Delete Customer Details")
print("3. Show all Customer Details")
print("4. Exit ")
ch=int(input("Enter your choice :"))
if ch==1:
li=eval(input("Enter cust.ID,Name,Phone number as list"))
dopush(stk,li)
elif ch==2:
item=dopop(stk)
if item=="Stack is empty":
print("Under flow... Stack is empty")
else:
print("Deleted item is:",item)
elif ch==3:
doshow(stk)
elif ch==4:
break
else:
print("Wrong choice")
OUTPUT