CBSE Class 12 Computer Science
Practical File (Python - 083)
Name: __________________________
Class: XII
School: _________________________
Session: 2025-26
Certificate
This is to certify that __________________ has successfully completed the Computer Science
Practical File based on Python programming and SQL as per CBSE Class 12 syllabus under
the guidance of the teacher.
Index
1. Sum of List
2. Factorial of Number
3. Prime Number Check
4. Fibonacci Series
5. Reverse String
6. Palindrome Check
7. File Handling (Read/Write)
8. Count Vowels
9. Dictionary Operations
10. Stack Implementation
11. Bubble Sort
12. Binary Search
13. CSV File Handling
14. Exception Handling
15. Basic MySQL Connectivity
SQL Queries
1. Sum of List
lst = [10,20,30,40]
print("Sum:", sum(lst))
2. Factorial of Number
n = int(input("Enter number: "))
fact = 1
for i in range(1, n+1):
fact *= i
print("Factorial:", fact)
3. Prime Number Check
n = int(input("Enter number: "))
for i in range(2, n):
if n % i == 0:
print("Not Prime")
break
else:
print("Prime")
4. Fibonacci Series
n = int(input("Enter terms: "))
a, b = 0, 1
for i in range(n):
print(a, end=" ")
a, b = b, a+b
5. Reverse String
s = input("Enter string: ")
print("Reverse:", s[::-1])
6. Palindrome Check
s = input("Enter string: ")
if s == s[::-1]:
print("Palindrome")
else:
print("Not Palindrome")
7. File Handling (Read/Write)
f = open("[Link]","w")
[Link]("Hello Python")
[Link]()
f = open("[Link]","r")
print([Link]())
8. Count Vowels
s = input("Enter string: ")
v = "aeiouAEIOU"
count = 0
for i in s:
if i in v:
count += 1
print("Vowels:", count)
9. Dictionary Operations
d = {"a":1, "b":2}
d["c"] = 3
print(d)
10. Stack Implementation
stack = []
[Link](10)
[Link](20)
print([Link]())
11. Bubble Sort
a = [5,2,9,1]
for i in range(len(a)):
for j in range(len(a)-i-1):
if a[j] > a[j+1]:
a[j], a[j+1] = a[j+1], a[j]
print(a)
12. Binary Search
a = [1,2,3,4,5]
key = 3
low, high = 0, len(a)-1
while low <= high:
mid = (low+high)//2
if a[mid] == key:
print("Found")
break
elif a[mid] < key:
low = mid+1
else:
high = mid-1
13. CSV File Handling
import csv
with open("[Link]","w") as f:
writer = [Link](f)
[Link](["Name","Marks"])
[Link](["Amit",90])
14. Exception Handling
try:
a = int(input("Enter number: "))
b = 10/a
print(b)
except:
print("Error")
15. MySQL Connectivity (Basic)
import [Link]
con =
[Link](host="localhost",user="root",password="1234",database="test")
print("Connected")
SQL Queries
1. Create Table:
CREATE TABLE student(id INT, name VARCHAR(20), marks INT);
2. Insert:
INSERT INTO student VALUES(1,'Amit',90);
3. Select:
SELECT * FROM student;
4. Update:
UPDATE student SET marks=95 WHERE id=1;
5. Delete:
DELETE FROM student WHERE id=1;