COMPUTER SCIENCE PROJECT REPORT (File
Handling and Stack Using List)
Sunrise Public School
Student Name: ____________________
Roll No.: ____________________
Teacher: Mrs. Neha Sharma
Class XII - CBSE Curriculum
CERTIFICATE
This is to certify that the project report entitled 'File Handling and Stack Using List' has been completed
successfully by the student of Class XII under the guidance of the Computer Science teacher. The work submitted
is original and completed according to CBSE guidelines.
Teacher Signature: ____________________
Principal Signature: ____________________
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to my Computer Science teacher for the valuable guidance and
support provided during the completion of this project. I also thank my school and parents for their
encouragement.
INDEX
[Link] Topic
1 Introduction to Python
2 File Handling in Python
3 Stack using List
4 Program 1
5 Program 2
6 Program 3
7 Program 4
8 Program 5
9 Program 6
10 Program 7
11 Program 8
12 Program 9
13 Program 10
14 Program 11
15 Program 12
16 Program 13
17 Program 14
18 Program 15
INTRODUCTION TO PYTHON
Python is a high-level, interpreted programming language known for its simple syntax and readability. It is widely
used in software development, web development, data science, artificial intelligence, automation, and education.
Python supports object-oriented programming and provides powerful libraries.
FILE HANDLING IN PYTHON
File handling allows users to store and retrieve data permanently using files. Python provides functions such as
open(), read(), write(), append(), and close() to perform file operations.
STACK USING LIST
A stack is a linear data structure that follows the LIFO (Last In First Out) principle. In Python, stacks can be
implemented using lists with operations such as push, pop, peek, and display.
PROGRAM 1
Aim: Write data to a file
Program:
f=open("[Link]","w")
[Link]("Welcome to Python")
[Link]()
print("Data written successfully")
Output: Data written successfully
PROGRAM 2
Aim: Read data from a file
Program:
f=open("[Link]","r")
print([Link]())
[Link]()
Output: Welcome to Python
PROGRAM 3
Aim: Append data to a file
Program:
f=open("[Link]","a")
[Link]("\nCBSE Project")
[Link]()
print("Data appended")
Output: Data appended
PROGRAM 4
Aim: Count number of lines in a file
Program:
f=open("[Link]","r")
lines=[Link]()
print("Total lines:",len(lines))
[Link]()
Output: Total lines: 2
PROGRAM 5
Aim: Count words in a file
Program:
f=open("[Link]","r")
data=[Link]()
words=[Link]()
print("Total words:",len(words))
[Link]()
Output: Total words: 5
PROGRAM 6
Aim: Copy content from one file to another
Program:
f1=open("[Link]","r")
f2=open("[Link]","w")
[Link]([Link]())
[Link]()
[Link]()
print("Copied successfully")
Output: Copied successfully
PROGRAM 7
Aim: Search a word in file
Program:
f=open("[Link]","r")
data=[Link]()
if "Python" in data:
print("Word Found")
else:
print("Word Not Found")
[Link]()
Output: Word Found
PROGRAM 8
Aim: Display file line by line
Program:
f=open("[Link]","r")
for line in f:
print(line)
[Link]()
Output: Welcome to Python
PROGRAM 9
Aim: Create stack using list
Program:
stack=[]
[Link](10)
[Link](20)
[Link](30)
print(stack)
Output: [10, 20, 30]
PROGRAM 10
Aim: Push operation in stack
Program:
stack=[]
n=int(input("Enter number: "))
[Link](n)
print(stack)
Output: [25]
PROGRAM 11
Aim: Pop operation in stack
Program:
stack=[10,20,30]
x=[Link]()
print("Deleted:",x)
print(stack)
Output: Deleted: 30
PROGRAM 12
Aim: Peek operation in stack
Program:
stack=[5,10,15]
print("Top element:",stack[-1])
Output: Top element: 15
PROGRAM 13
Aim: Display stack elements
Program:
stack=[1,2,3,4]
for i in reversed(stack):
print(i)
Output: 4 3 2 1
PROGRAM 14
Aim: Check stack underflow
Program:
stack=[]
if len(stack)==0:
print("Stack Underflow")
else:
print([Link]())
Output: Stack Underflow
PROGRAM 15
Aim: Menu driven stack program
Program:
stack=[]
while True:
print("[Link] [Link] [Link] [Link]")
ch=int(input("Enter choice: "))
if ch==1:
n=int(input("Enter number: "))
[Link](n)
elif ch==2:
if len(stack)==0:
print("Underflow")
else:
print("Deleted:",[Link]())
elif ch==3:
print(stack)
elif ch==4:
break
Output: Menu Driven Output
VIVA QUESTIONS
• What is file handling in Python?
• What is the use of open() function?
• What is a stack?
• What is LIFO?
• What is the difference between write and append mode?
• What is stack overflow and underflow?
BIBLIOGRAPHY
1. NCERT Computer Science Book for Class XII
2. Python Documentation
3. CBSE Curriculum Guidelines