Practical File
Computer Science (083)
Term - I
(2025-26)
Submitted By
Name:
Roll Number:
Class & Section:
Rosary Senior Secondary School
Radio Colony, Kingsway Camp
Delhi – 110009
Page 1 of 6
INDEX
[Link] Practical Description Page No. Signature
1. WAP to swap/exchange the values of two variables.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Page 2 of 6
Program No: 01
Write a Python program to implement a stack using list.
Source Code:
# Implementation of stack using list
st=[] #to create an empty list
def stkpush():
n=int(input("Enter a No. : "))
[Link](n)
def stkpop():
if st==[]:
print("Stack Underflow/Stack is Empty")
else:
print([Link]()," removed")
def display():
if st==[ ]:
print("Stack Underflow/Stack is empty")
else:
print("STACK CONTENTS: ")
L=len(st)-1
for i in range(L,-1,-1):
print(st[i])
while True:
Page 3 of 6
print('***STACK DEMONSTRATION***')
print('***1. PUSH***')
print('***2. POP***')
print('***3. DISPLAY***')
choice=int(input('Enter your choice (1-3) to continue and other than (1-3) to Exit'))
if choice==1:
stkpush()
elif choice==2:
stkpop()
elif choice==3:
display()
else:
print('Wrong choice')
break
Sample Input and Output:
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit3
Stack Underflow/Stack is empty
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit1
Enter a No. : 10
Page 4 of 6
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit1
Enter a No. : 20
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit3
STACK CONTENTS:
20
10
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit2
20 removed
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit2
10 removed
***STACK DEMONSTRATION***
***1. PUSH***
Page 5 of 6
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit2
Stack Underflow/Stack is Empty
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit3
Stack Underflow/Stack is empty
***STACK DEMONSTRATION***
***1. PUSH***
***2. POP***
***3. DISPLAY***
Enter your choice (1-3) to continue and other than (1-3) to Exit4
Wrong choice
Page 6 of 6