0% found this document useful (0 votes)
32 views

Program No 17 Stack Operation

The document presents a Python program that uses functions to implement a stack to push, pop, and display customer details including ID, name, and phone number. The program contains functions for checking if the stack is empty, pushing items onto the stack, popping items off the stack, and displaying all items in the stack. It uses a while loop to get user input to perform these stack operations and displays output.

Uploaded by

Muthumeenatchi U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Program No 17 Stack Operation

The document presents a Python program that uses functions to implement a stack to push, pop, and display customer details including ID, name, and phone number. The program contains functions for checking if the stack is empty, pushing items onto the stack, popping items off the stack, and displaying all items in the stack. It uses a while loop to get user input to perform these stack operations and displays output.

Uploaded by

Muthumeenatchi U
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Date : 04.01.

2022 Program No :17

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

1. Insert Customer Details


2. Delete Customer Details
3. Show all Customer Details
4. Exit
Enter your choice :1
Enter cust.ID,Name,Phone number as list[1,'raja',7896541236]
Values Inserted
1. Insert Customer Details
2. Delete Customer Details
3. Show all Customer Details
4. Exit
Enter your choice :1
Enter cust.ID,Name,Phone number as list[2,'vinoth',5698741236]
Values Inserted
1. Insert Customer Details
2. Delete Customer Details
3. Show all Customer Details
4. Exit
Enter your choice :3
[2, 'vinoth', 5698741236]
[1, 'raja', 7896541236]
1. Insert Customer Details
2. Delete Customer Details
3. Show all Customer Details
4. Exit
Enter your choice :2
Deleted item is: [2, 'vinoth', 5698741236]
1. Insert Customer Details
2. Delete Customer Details
3. Show all Customer Details
4. Exit
Enter your choice :4

You might also like