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

Python Stack Implementation for Employee Data

The document outlines a Python program that implements a stack to manage employee details, including employee number and name. It includes functions for checking if the stack is empty, pushing new employee records, popping the most recent record, and displaying all records. The program runs in a loop allowing users to choose actions until they decide to exit.
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)
5 views2 pages

Python Stack Implementation for Employee Data

The document outlines a Python program that implements a stack to manage employee details, including employee number and name. It includes functions for checking if the stack is empty, pushing new employee records, popping the most recent record, and displaying all records. The program runs in a loop allowing users to choose actions until they decide to exit.
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

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']

You might also like