CBSE Class 12 · Computer Science · Practical
CBSE Class 12 Computer Science Practical File — Python Programs with Output
The CBSE Class 12 Computer Science (083) practical is 30 marks — and the report file needs a minimum of 15 Python programs and 5 SQL query sets. Here are ready, run-verified Python programs (with their actual output) covering the most common practical topics. Copy, understand, and practise.
1. Stack using a list (push, pop, display)
Program
stack = []
def push(item):
stack.append(item)
def pop():
if not stack:
return "Stack Empty"
return stack.pop()
push(10); push(20); push(30)
print("Stack:", stack)
print("Popped:", pop())
print("Stack after pop:", stack)Output
Stack: [10, 20, 30] Popped: 30 Stack after pop: [10, 20]
2. Factorial of a number using recursion
Program
def factorial(n):
if n == 0 or n == 1:
return 1
return n * factorial(n - 1)
num = 5
print("Factorial of", num, "is", factorial(num))Output
Factorial of 5 is 120
3. Count vowels and consonants in a string
Program
text = "Kwickprep Computer Science"
vowels = consonants = 0
for ch in text.lower():
if ch.isalpha():
if ch in "aeiou":
vowels += 1
else:
consonants += 1
print("Vowels:", vowels)
print("Consonants:", consonants)Output
Vowels: 8 Consonants: 16
4. Linear search in a list
Program
def linear_search(arr, key):
for i in range(len(arr)):
if arr[i] == key:
return i
return -1
data = [12, 45, 7, 23, 56, 89]
pos = linear_search(data, 23)
print("Found at index" , pos) if pos != -1 else print("Not found")Output
Found at index 3
5. Count frequency of each word in a sentence
Program
sentence = "python is easy python is fun"
words = sentence.split()
freq = {}
for w in words:
freq[w] = freq.get(w, 0) + 1
print(freq)Output
{'python': 2, 'is': 2, 'easy': 1, 'fun': 1}6. Print Fibonacci series up to n terms
Program
n = 8
a, b = 0, 1
print("Fibonacci:", end=" ")
for i in range(n):
print(a, end=" ")
a, b = b, a + bOutput
Fibonacci: 0 1 1 2 3 5 8 13
7. Binary file: write & read student records (pickle)
Program
import pickle
students = [{"roll": 1, "name": "Asha", "marks": 92},
{"roll": 2, "name": "Ravi", "marks": 85}]
with open("students.dat", "wb") as f:
pickle.dump(students, f)
with open("students.dat", "rb") as f:
data = pickle.load(f)
for s in data:
print(s["roll"], s["name"], s["marks"])Output
1 Asha 92 2 Ravi 85
8. Reverse a string using a stack
Program
def reverse(text):
stack = list(text)
result = ""
while stack:
result += stack.pop()
return result
print(reverse("KWICKPREP"))Output
PERPKCIWK
Get the full practical-file pack — free
15+ programs, the exact CBSE practical-file format, SQL query sets and likely viva questions — sent on WhatsApp.
Get it on WhatsAppRelated: CS 083 weightage · Try code in the Python Playground · Project ideas

