Stack
Stack
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.