Finally Yy Yyy Yyy
Finally Yy Yyy Yyy
This is to certify that Krush Ranjit Horo of class XII 'A' has
successfully completed the Computer Science project file
under the supervision of Miss Preeti Singh.
Principal Signature
1
ACKNOWLEDGEMENT
I would like to express my heartfelt gratitude to my Computer
Science teacher Miss Preeti Singh and Fr. Ignatius Lakra
who gave me the opportunity to do this project, which helped
in doing a lot of research and I came to know about so many
new things. I am very thankful to them.
2
INDEX
SL TITLE PAGE
No. NO.
1 Read a text file line by line and display each word 5
separated a #.
2 Read a text file and display the number of 6-7
vowels/consonants/uppercase/lower case characters in the
file.
3 Remove all the lines that contain the character 'A' in a file 8
and write it to another file
4 Create binary file with the name and roll no, search for a 9-10
given roll no and display the name if not found display
appropriate message.
5 Create a binary file with roll no, name and mark. Input a 11-13
roll no. and update the marks.
6 Write a random number generator that generate random 13
number between 1 and 6.
7 Write a python program to implement stack using list. 14-15
8 Create a CSV file by entering user id and password, read 16-17
and search the password for given user id.
9 Write a python program to implement step operations 18-20
using dictionary.
10 Write a python program to create and search records in 21-22
binary files.
11 Write a python program to perform 23-24
mathematical operations.
12 Write a program to create menu-driven program to find 25-26
factorial and sum of list of numbers using function.
13 Write a python program to implement returning 265
values from function.
14 Write a program to add data to existing data in file. 27
15 Write a program to copy a content of a file to another file. 28
16 Create a student table and insert data. Implement the 29-31
following SQL command on the student table:-
3
1. Alter table to add new attributes modified data
type/drop attribute.
2. Update table to modify data.
3. Order by to display data in ascending/descending
order.
4. Delete to remove tuples. Group by and find the min,
max, sum, count and average.
17 Conclusion 32
18 Bibliography 33
4
1. Read a text file line by line and display each word
separated a #.
Program:
5
2. Read a text file and display the number of vowels/
consonants/ uppercase/ lower case characters in
the file.
Program:
6
consonants_count += 1
if char.isupper():
uppercase_count += 1
elif char.islower():
lowercase_count += 1
7
3. Remove all the lines that contain the character 'A'
in a file and write it to another file.
Program:
# Open the original file in read mode and the new file in write
mode
with open('inputfile.txt', 'r') as infile, open('outputfile.txt', 'w') as
outfile:
# Loop through each line in the input file
for line in infile:
# Check if the line contains 'A'
if 'A' not in line:
# Write the line to the output file if 'A' is not in it
outfile.write(line)
8
4. Create binary file with the name and roll no,
search for a given roll no and display the name if
not found display appropriate message.
Program:
import pickle
9
pass # Reached end of file
if not found:
print("Roll number not found.")
10
5. Create a binary file with roll no, name and mark.
Input a roll no. and update the marks.
Program:
import pickle
if updated:
print(f"Marks updated for roll number {roll_no_to_update}.")
else:
print(f"Roll number {roll_no_to_update} not found.")
import random
def generate_random_number():
return random.randint(1, 6)
13
7. Write a python program to implement stack using
list. 777
Program:
class Stack:
def __init__(self):
self.items = []
def is_empty(self):
return len(self.items) == 0
def pop(self):
if self.is_empty():
raise IndexError("pop from empty stack")
return self.items.pop()
def peek(self):
if self.is_empty():
raise IndexError("peek from empty stack")
return self.items[-1]
def size(self):
return len(self.items)
14
def __str__(self):
return str(self.items)
# Example usage:
if __name__ == "__main__":
stack = Stack()
stack.push(1)
stack.push(2)
stack.push(3)
15
8. Create a CSV file by entering user id and
password, read and search the password for given
user id.
Program:
import csv
16
if row['user_id'] == user_id_to_search:
print(f"Password for user ID '{user_id_to_search}' is:
{row['password']}")
return
print("User ID not found.")
17
9. Write a python program to implement step
operations using dictionary
Program:
class StepManager:
def __init__(self):
self.steps = {}
18
if step_id in self.steps:
del self.steps[step_id]
print(f"Deleted step {step_id}.")
else:
print(f"Step {step_id} not found.")
def list_steps(self):
if not self.steps:
print("No steps available.")
else:
for step_id, description in self.steps.items():
print(f"Step {step_id}: {description}")
# Example usage
if __name__ == "__main__":
manager = StepManager()
while True:
action = input("Choose an action: add, update, get, delete,
list, or exit: ")
if action == 'add':
step_id = input("Enter step ID: ")
description = input("Enter step description: ")
manager.add_step(step_id, description)
elif action == 'update':
step_id = input("Enter step ID to update: ")
19
new_description = input("Enter new description: ")
manager.update_step(step_id, new_description)
elif action == 'get':
step_id = input("Enter step ID to retrieve: ")
print(manager.get_step(step_id))
elif action == 'delete':
step_id = input("Enter step ID to delete: ")
manager.delete_step(step_id)
elif action == 'list':
manager.list_steps()
elif action == 'exit':
break
else:
print("Invalid action. Please choose again.")
20
10. Write a python program to create and search
records in binary files.
Program:
import pickle
21
if not found:
print("Record not found.")
# Main program
filename = 'students.dat'
# Create records
create_records(filename)
22
11. Write a python program to perform
mathematical operations.
Program:
def main():
print("Welcome to the Simple Calculator")
print("Select operation:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
23
while True:
choice = input("Enter choice (1/2/3/4 or 'exit' to quit): ")
if choice.lower() == 'exit':
print("Exiting the calculator. Goodbye!")
break
if choice == '1':
print(f"{num1} + {num2} = {add(num1, num2)}")
else:
print("Invalid input. Please choose a valid operation.")
if _name_ == "_main_":
main()
24
12. Write a program to create menu-driven program
to find factorial and sum of list of numbers using
function.
Program:
import math
def factorial(n):
return math.factorial(n)
def sum_of_list(numbers):
return sum(numbers)
while True:
choice = input("\nChoose (1: Factorial, 2: Sum of List, 3: Exit): ")
if choice == '1':
num = int(input("Enter number: "))
print("Factorial:", factorial(num))
25
break
else:
print("Invalid choice.")
Program
26
14. Write a program to add data to existing data in
file.
Program:
# Main program
filename = "example.txt"
data = input("Enter data to append to the file: ")
append_to_file(filename, data)
27
15. Write a program to copy a content of a file to
another file.
Program:
# Main program
source_file = "source.txt"
destination_file = "destination.txt"
copy_file(source_file, destination_file)
print(f"Content copied from {source_file} to {destination_file}.")
28
16. Create a student table and insert data.
Implement the following SQL command on the
student table:-
1. Alter table to add new attributes modified data
type/drop attribute
2. Update table to modify data
3. Order by to display data in
ascending/descending order.
4. Delete to remove tuples. Group by and find the
min, max, sum, count and average.
Code:
-- Create the student table
CREATE TABLE student (
id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
age INT,
grade DECIMAL(4, 2)
);
-- Insert data into the student table
INSERT INTO student (id, name, age, grade) VALUES (1, 'Alice', 20,
85.5);
INSERT INTO student (id, name, age, grade) VALUES (2, 'Bob', 22,
90.0);
INSERT INTO student (id, name, age, grade) VALUES (3, 'Charlie',
19, 72.5);
29
INSERT INTO student (id, name, age, grade) VALUES (4, 'David', 21,
88.0);
INSERT INTO student (id, name, age, grade) VALUES (5, 'Eve', 20,
91.0);
30
-- Display students ordered by grade in ascending order
SELECT * FROM student ORDER BY grade ASC;
-- Display students ordered by grade in descending order
SELECT * FROM student ORDER BY grade DESC;
31
CONCLUSION
Here I have come to the end of the computer science project.
It was a wonderful and learning experience for me while
working on this project. This project took me through various
aspects of project and taught me about research and findings.
It also gave me a real insight into this project topic. I learned
about problem solving and how to deal with challenges. This
project increased my research, thinking skill and interest in
this subject.
Thank you for giving me this project I enjoyed every bit of it.
32
BIBLIOGRAPHY
For successfully completing my project file. I have taken help
from the following website –
https://chatgpt.com/
https://www.mycompiler.io
https://stackoverflow.com
https://www.studocu.com/in/document/kv-ranga-reddy-law-
college/computer-science/cs-practical-programs/44590985
33