PROGRAM NO: 15
AIM:
To write a Python program to implement a stack for the employee details (empno, ename).
SOURCE CODE:
stk = []
top = -1
limit = 0
def isempty():
global stk
if stk == []:
print("Stack is empty!!!")
return True
else:
return False
def push():
global stk, top
empno = int(input("Enter the employee number to push: "))
ename = input("Enter the employee name to push: ")
[Link]([empno, ename])
top += 1
def pop():
global stk, top
if isempty():
pass
else:
print("Deleted record is:", stk[top])
[Link]()
top -= 1
def display():
global stk, top
if isempty():
pass
else:
print("The stack elements are:")
for i in range(top, -1, -1):
print(stk[i])
# Main program
while True:
print("\n1. PUSH\n2. POP\n3. DISPLAY\n4. EXIT")
ch = int(input("Enter your choice: "))
if ch == 1:
push()
elif ch == 2:
pop()
elif ch == 3:
display()
elif ch == 4:
break
else:
print("Invalid choice")
RESULT:
Thus, the above Python program is executed successfully and the output is
verified.
SAMPLE OUTPUT 1:
1. PUSH
2. POP
3. DISPLAY
4. EXIT
Enter your choice: 1
Enter the employee number to push: 101
Enter the employee name to push: John
Enter your choice: 1
Enter the employee number to push: 102
Enter the employee name to push: Alice
Enter your choice: 3
The stack elements are:
[102, 'Alice']
[101, 'John']
SAMPLE OUTPUT 2:
Enter your choice: 2
Deleted record is: [102, 'Alice']
Enter your choice: 3
The stack elements are:
[101, 'John']