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

Program File CS

The document is a program file for Computer Science submitted by a student named Yakksheeta at Millennium World School for the session 2025-26. It includes a certificate of completion, acknowledgments, and a comprehensive table of contents listing various programming tasks and SQL commands, along with code snippets and expected outputs. The tasks cover file handling, data manipulation, and basic algorithms in Python, demonstrating the student's understanding of computer science concepts.

Uploaded by

Yakksheeta jhamb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views28 pages

Program File CS

The document is a program file for Computer Science submitted by a student named Yakksheeta at Millennium World School for the session 2025-26. It includes a certificate of completion, acknowledgments, and a comprehensive table of contents listing various programming tasks and SQL commands, along with code snippets and expected outputs. The tasks cover file handling, data manipulation, and basic algorithms in Python, demonstrating the student's understanding of computer science concepts.

Uploaded by

Yakksheeta jhamb
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Millennium World School,

FARIDABAD

Session-2025-26

COMPUTER SCIENCE
PROGRAM FILE
Submitted To – Ms. Kajol Tiwari
Submitted By – Yakksheeta
Class – XII

1 | Page
CERTIFICATE

This is to certify that YAKKSHEETA of class XII of


MILLENNIUM WORLD SCHOOL has completed his
programs under my supervision. He has taken an
interest and has shown at most sincerity in the
completion of programs.
I certify these programs up to my expectation & as
per guidelines issued by CBSE, NEW DELHI.

Internal Examiner External Examiner

2 | Page
ACKNOWLEDGMENT

It is with pleasure that I acknowledge my sincere


gratitude to our teacher who taught and
undertook the responsibility of teaching the
subject computer science. I have been greatly
benefited from his classes.
I am especially indebted to our Principal who has
always been a source of encouragement and
support and without whose inspiration this
project would not have been a successful I would
like to place on record heartfelt thanks to him.
Finally, I would like to express my sincere
appreciation for all the other students for my
batch their friendship & the fine time that we all
shared together.

3 | Page
TABLE OF CONTENTS

[Link]. Topic [Link]


1 Write a program to read text file line by line
and display each word separated by #.
2 Write program to read a text file and
display the number of vowels/ consonants/
uppercase/ lowercase characters in the file.
Remove all the lines that contain the
3
character 'a' in a file and write in to another
file.
4 Create a binary file with name and roll
number. Search for a given roll number and
display the name, if not found display
appropriate message.
5 Create a binary file with roll number, name
and marks. Input a roll number and update
the marks.
6 Write a random number generator that
generates random numbers between 1 and
6 (simulates a dice)
7 Write a program to read file line by line.

8 Create a CSV file by entering user ID and


password, reach and search the password
for given user-id.
9 Write a python program to make a
calculator
10 Write a program to sort the list by Bubble
sort technique.

4 | Page
11 Write a program to sort the list by insertion
technique.
12 Write a program to sort the list by selection
technique.
13 Write a program using stack for operation
push and pop.
14 Write a program using stack for operation
push and peek.
15 Write a program using stack for operation
push and display.
16 Write a program to connect mysql and
create a table.
17 Write a program to connect mysql and
insert data in table.
18 Write a program to select all records and
display data from table.

5 | Page
SQL COMMANDS
[Link] Programs [Link]
1. Write sql command to create a
database and then create table
2. Write a sql command to insert values
into the table.
3. Write sql command to distinct values
from table.
4. Write sql command to update salary
from employee_id where emp_id is
'10003'.
5. Write sql command to add new column
and delete it into the table.
6. Write sql command to display details of
all column of table in descending order
of employee name.
7. Write sql command to display all
columns grouped by emp_name in
descending order.

6 | Page
Write a program to read text file line by line and display each word separated
by #

f = open("[Link]")
for line in f:
words = [Link]()
for w in words:
print(w+'#',end='')
print()
[Link]()

Output:

Hello#World
This#is#a#test
Python#programming#is#fun

7 | Page
Write program to read a text file and display the number of vowels/
consonants/ uppercase/ lowercase characters in the file

def count_characters(file_name):
vowels = 'aeiouAEIOU'
try:
with open(‘[Link]’, 'r') as file:
text = [Link]()
vowel_count = sum(1 for char in text if char in
vowels)
consonant_count = sum(1 for char in text if
[Link]() and char not in vowels)
uppercase_count = sum(1 for char in text if
[Link]())
lowercase_count = sum(1 for char in text if
[Link]())
print(f"Vowels: {vowel_count}")
print(f"Consonants: {consonant_count}")
print(f"Uppercase: {uppercase_count}")
print(f"Lowercase: {lowercase_count}")
except FileNotFoundError:
print(f"[Link]' not found.")
count_characters([Link])

Output:

Vowels: 27
Consonants: 55
Uppercase: 13
Lowercase: 69

8 | Page
Remove all the lines that contain the character 'a' in a file and write in to
another file

f1=open(“[Link]','r')
f2=open('[Link]','w')
l=[Link]()
for i in l:
if 'a' in i:
i=[Link]('a','')
[Link](i)
[Link]()
[Link]()

OUTPUT
NOTE: After copy content of file2
one two three four
five six seven
eight nine ten
bye!

9 | Page
Create a binary file with name and roll number. Search for a given roll
number and display the name, if not found display appropriate message
import pickle
student=[]
f=open('[Link]','wb')
ans='y'
while [Link]()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
_ [Link]([roll,name])
ans=input("Add More ?(Y)") [Link](student,f)
[Link]()
f=open('[Link]','rb')
student=[]
while True:
try:
student = [Link](f)
except EOFError:
break
ans='y'
while [Link]()=='y':
found=False
r = int(input("Enter Roll number to search :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
_ found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Search more ?(Y) :") [Link]()

OUTPUT
Enter Roll Number :1
Enter Name :Amit
Add More ?(Y)y
Enter Roll Number :2
Enter Name :Jasbir
Add More ?(Y)y
Enter Roll Number :3
Enter Name :Vikral
Add More ?(Y)n
Enter Roll number to search :2
## Name is : Jasbir
## Search more ?(Y) :y
Enter Roll number to search :1##
Name is : Amit ##
Search more ?(Y) :y
Enter Roll number to search :4
####Sorry! Roll number not found ####
Search more ?(Y) :n

10 | P a g e
Create a binary file with roll number, name and marks. Input a roll
number and update the marks
import pickle

def create_binary_file(f):
student_data = []
while True:
rollno = int(input("Enter roll number: "))
name = input("Enter name: ")
marks = int(input("Enter marks: "))
student_data.append([rollno, name, marks])
choice = input("Do you want to add more records?
(y/n): ")
if [Link]() != 'y':
break
with open(“[Link]”,'wb') as file:
[Link](student_data, file)

def update_marks(file):
rollno = int(input("Enter roll number to update marks: "))
with open(file_name, 'rb') as file:
student_data = [Link](file)
for student in student_data:
if student[0] == rollno:
student[2] = int(input("Enter new marks: "))
break
with open([Link], 'wb') as file:
[Link](student_data, file)

def main():

11 | P a g e
file_name = 'student_data.bin'
create_binary_file(f)
update_marks(file)
with open([Link], 'rb') as file:
student_data = [Link](file)
print("Updated Student Data:")
for student in student_data:
print(f"Roll No: {student[0]}, Name: {student[1]},
Marks: {student[2]}")

if name == " main ":


main()

Output:

Enter roll number: 1


Enter name: John
Enter marks: 90
Do you want to add more records? (y/n): y
Enter roll number: 2
Enter name: Alice
Enter marks: 85
Do you want to add more records? (y/n): n
Enter roll number to update marks: 1
Enter new marks: 95
Updated Student Data:
Roll No: 1, Name: John, Marks: 95
Roll No: 2, Name: Alice, Marks: 85

12 | P a g e
Write a random number generator that generates random numbers
between 1 and 6 (simulates a dice)

import random

def roll_dice():
sides = int(input("Enter the number of
sides on the dice: "))
return [Link](1, sides)

print("You rolled a:", roll_dice())

OUTPUT

Enter the number of sides on the dice: 6


You rolled a: 3

Write a program to read file line by line


def read_file(file_name):
try:
with open(file_name, 'r') as file:
for line in file:
print([Link]())
except FileNotFoundError:
print(f"File '{file_name}' not found.")

read_file('[Link]')

OUTPUT
Hello World
This is a test

13 | P a g e
Write a program to read file line by line

def read_file(file_name):
try:
with open(file_name, 'r') as file:
for line in file:
print([Link]())
except FileNotFoundError:
print(f"File '{file_name}' not found.")

read_file('[Link]')

OUTPUT

Hello World
This is a test
Python programming is fun

Create a CSV file by entering user ID and password, reach and search
the password for given user-id

import csv

def create_csv_file(file_name):
with open(file_name, 'w', newline='') as file:
writer = [Link](file)
[Link](["User ID", "Password"])
while True:
user_id = input("Enter User ID: ")
password = input("Enter Password: ")
[Link]([user_id, password])
choice = input("Do you want to add mor
records? (y/n): ")
if [Link]() != 'y':
break

def search_password(file_name, user_id):

14 | P a g e
with open(file_name, 'r') as file:
reader = [Link](file)
next(reader) # Skip header row
for row in reader:
if row[0] == user_id:
return row[1]
return None

def main():
file_name = 'user_credentials.csv'
create_csv_file(file_name)
user_id = input("Enter User ID to search password: ")
password = search_password(file_name, user_id)
if password:
print(f"Password for User ID {user_id} is: password}")
else:
print(f"No password found for User ID {user_id}")

if name == " main ":


main()

Output:

Enter User ID: user1


Enter Password: pass1
Do you want to add more records? (y/n): y
Enter User ID: user2
Enter Password: pass2
Do you want to add more records? (y/n): n
Enter User ID to search password: user1
Password for User ID user1 is: pass1

15 | P a g e
Write a python program to make a calculator
def add(x, y):
return x + y

def subtract(x, y):


return x - y

def multiply(x, y):


return x * y

def divide(x, y):


if y == 0:
return "Error: Division by zero is not allowed"
else:
return x / y

def calculator():
while True:
print("\nCalculator Menu:")
print("1. Addition")
print("2. Subtraction")
print("3. Multiplication")
print("4. Division")
print("5. Quit")

choice = input("Enter your choice (1-5): ")

if choice in ['1', '2', '3', '4']:


num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))

if choice == '1':
print(f"{num1} + {num2} = {add(num1, num2)}")
elif choice == '2':
print(f"{num1} - {num2} = {subtract(num1, num2)}")
elif choice == '3':
print(f"{num1} * {num2} = {multiply(num1, num2)}")
elif choice == '4':
print(f"{num1} / {num2} = {divide(num1, num2)}")

elif choice == '5':


16 | P a g e
print("Goodbye!")
break

else:
print("Invalid choice. Please try again.")

calculator()

Output:

Calculator Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Quit
Enter your choice (1-5): 1
Enter first number: 10
Enter second number: 5
10.0 + 5.0 = 15.0

Calculator Menu:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Quit
Enter your choice (1-5): 5
Goodbye

17 | P a g e
Write a program to sort the list by Bubble sort technique

def bubble_sort(lst):
n = len(lst)
for i in range(n):
for j in range(0, n - i - 1):
if lst[j] > lst[j + 1]:
lst[j], lst[j + 1] = lst[j + 1], lst[j]
return lst

lst = [64, 34, 25, 12, 22, 11, 90]


print("Original list:", lst)
print("Sorted list:", bubble_sort(lst))

Output:

Original list: [64, 34, 25, 12, 22, 11, 90]


Sorted list: [11, 12, 22, 25, 34, 64, 90]

Write a program to sort the list by insertion technique

def insertion_sort(lst):
for i in range(1, len(lst)):
key = lst[i]
j=i-1
while j >= 0 and lst[j] > key:
lst[j + 1] = lst[j]
j -= 1
lst[j + 1] = key
return lst

lst = [64, 34, 25, 12, 22, 11, 90]


print("Original list:", lst)
print("Sorted list:", insertion_sort(lst))

Output:
Original list: [64, 34, 25, 12, 22, 11, 90]
Sorted list: [11, 12, 22, 25, 34, 64, 90]

18 | P a g e
Write a program to sort the list by selection technique
def selection_sort(lst):
for i in range(len(lst)):
min_index = i
for j in range(i + 1, len(lst)):
if lst[j] < lst[min_index]:
min_index = j
lst[i], lst[min_index] = lst[min_index], lst[i]
return lst

lst = [64, 34, 25, 12, 22, 11, 90]


print("Original list:", lst)
print("Sorted list:", selection_sort(lst))

Output:

Original list: [64, 34, 25, 12, 22, 11, 90]


Sorted list: [11, 12, 22, 25, 34, 64, 90]

Write a program using stack for operation push and pop


class Stack:
def __init__(self):
[Link] = []

def push(self, item):


[Link](item)

def pop(self):
if not self.is_empty():
return [Link]()
else:
return "Stack is empty"

def is_empty(self):
return len([Link]) == 0

# Create a stack
s = Stack()
# Push operations

19 | P a g e
[Link](1)
[Link](2)
[Link](3)

# Pop operations
print([Link]()) # Output: 3
print([Link]()) # Output: 2
print([Link]()) # Output: 1
print([Link]()) # Output: Stack is empty

Write a program using stack for operation push and peek

class Stack:
def __init__(self):
[Link] = []

def push(self, item):


[Link](item)

def peek(self):
if not self.is_empty():
return [Link][-1]
else:
return "Stack is empty"

def is_empty(self):
return len([Link]) == 0

# Create a stack
s = Stack()
# Push operations
[Link](1)
[Link](2)
[Link](3)
# Peek operation
print([Link]()) # Output: 3
print([Link]()) # Output: 3
[Link](4)
print([Link]()) # Output: 4

20 | P a g e
Write a program using stack for operation push and display

class Stack:
def init (self):
[Link] = []

def push(self, item):


[Link](item)

def display(self):
return [Link]

# Create a stack
s = Stack()

# Push operations
[Link](1)
[Link](2)
[Link](3)

# Display operation
print([Link]()) # Output: [1, 2, 3]
[Link](4)
print([Link]()) # Output: [1, 2, 3, 4]
[Link](5)
print([Link]()) # Output: [1, 2, 3, 4, 5]

21 | P a g e
Write a program to connect mysql and create a table

import [Link]
db = [Link](
host="localhost",
user="root",
password="12345")
cursor = [Link]()
[Link]("CREATE DATABASE IF NOT EXISTS mydatabase")
[Link]("USE mydatabase")
[Link]("""
CREATE TABLE IF NOT EXISTS customers (
id INT AUTO_INCREMENT,
name VARCHAR(255),
email VARCHAR(255),
PRIMARY KEY (id))
""")
[Link]()
[Link]()

Write a program to connect mysql and insert data in table

import [Link]
db = [Link](
host="localhost",
user="root",
password="12345",
database="mydatabase")
cursor = [Link]()
sql = "INSERT INTO customers (name, email) VALUES (%s, %s)"
val = ("John Doe", "john@[Link]")
[Link](sql, val)
[Link]()
print([Link], "record inserted")
[Link]()
[Link]()

OUTPUT
1 record inserted

22 | P a g e
Write a program to select all records and display data from table

import [Link]

db = [Link](
host="localhost",
user="root",
password="12345",
database="mydatabase")

cursor = [Link]()
[Link]("SELECT * FROM customers")
result = [Link]()
for row in result:
print(row)
[Link]()
[Link]()

OUTPUT
(1, 'John Doe', 'john@[Link]')

23 | P a g e
Write sql command to create a database and then create table

CREATE DATABASE mydatabase;


USE mydatabase;
CREATE TABLE customers (
id INT AUTO_INCREMENT,
name VARCHAR(255),
email VARCHAR(255),
PRIMARY KEY (id)
);

OUTPUT

+ + + + + +
| Field| Type | Null | Key | Default | Extra |
+ + + + + +
|id | int | NO | PRI | NULL | auto_increment |
|name| varchar(255)| YES | | NULL | |
|email| varchar(255)| YES | | NULL | |
+ + + + + +

Write a sql command to insert values into the table

INSERT INTO customers (name, email)


VALUES ('John Doe', 'john@[Link]');

OUTPUT

+ + + +
| id | name | email |
+ + + +
| 1 | John Doe | john@[Link] |
+ + + +

24 | P a g e
Write sql command to distinct values from table

SELECT DISTINCT name, email FROM customers;

OUTPUT

+ + +
|name | email |
+ + +
|John Doe | john@[Link] |
+ + +

Write sql command to update salary from employee_id where emp_id is


'10003'
UPDATE employees SET salary = 50000 WHERE emp_id = '10003';

OUTPUT

emp_id FirstName LastName Email PhoneNo Salary


10003 John King [Link]@[Link] 9756797567 50000
10004 Anna Libert [Link]@[Link] 999998888 67000

25 | P a g e
Write sql command to add new column and delete it into the table

Add new column:


ALTER TABLE customers ADD COLUMN department VARCHAR(255);

OUTPUT
+ + + + +
| id | name | email |department |
+ + + + +
| 1 | John Doe | john@[Link] |NULL |
+ + + + +

Delete column:
ALTER TABLE employees DROP COLUMN department;

OUTPUT
+ + + +
| id | name | email |
+ + + +
| 1 | John Doe | john@[Link] |
+ + + +

Write sql command to display details of all column of table in descending


order of employee name

SELECT * FROM customers ORDER BY name DESC;

OUTPUT
+ + + +
| id | name | email |
+ + + +
| 1 | John Doe | john@[Link] |
| 2 | Anna Libert | [Link]@[Link] |
+ + + +

26 | P a g e
Write sql command to display all columns grouped by emp_name in
descending order

SELECT * FROM employees GROUP BY emp_name ORDER BY name DESC;

OUTPUT
+ +
| emp_name |
+ +
|John Doe |
|Anna Libert |
+ +

27 | P a g e
REFERENCES
1. News API
[Link]

2. Wikipedia
[Link]

3. Python
[Link]

4. MySQL
[Link]

5. ANSI Escape Codes in Python


• [Link]
• [Link]
Codes-in- Python/22803
• [Link]
d/9e584a7dd2935d0f461904b9f2950007

6. Class 11th & 12th Computer Science Arihant Books

28 | P a g e

You might also like