0% found this document useful (0 votes)
13 views2 pages

Stack

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)
13 views2 pages

Stack

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/ 2

AIM: Write a menu driven program on a stack containing employee

names
 CODE
def push(employee):
h = input("Enter a name: ")
employee.append(h)

def pop(employee):
if len(employee) == 0:
print("No name to delete")
else:
print("Deleted name is:", employee.pop())

def display(employee):
print(employee)

employee = []
while True:
print("1. Add name")
print("2. Delete name")
print("3. Display names")
print("4. Exit")
op = int(input("Enter the Choice: "))
if op == 1:
push(employee)
elif op == 2:
pop(employee)
elif op == 3:
display(employee)
elif op == 4:
print("Exiting program.")
break
else:
print("Invalid choice. Please enter a number between 1 and 4.")

 Output
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 1
Enter a name: Prajwal
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 1
Enter a name: Amrita
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 1
Enter a name: Kavya
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 1
Enter a name: Drishti
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 3
['Prajwal', 'Amrita', 'Kavya', 'Drishti']
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 2
Deleted name is: Drishti
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 3
['Prajwal', 'Amrita', 'Kavya']
1. Add name
2. Delete name
3. Display names
4. Exit
Enter the Choice: 4
Exiting program.

You might also like