Exam Prep
How to Prepare for CBSE Computer Science Practical Exam, Complete Guide
Complete guide to prepare for CBSE Class 12 CS practical exam. Covers Python programs, SQL queries, project work, viva questions, and scoring tips.
The CBSE Class 12 Computer Science practical exam carries 30 marks - nearly one-third of your total score. Many students lose marks here due to poor preparation. This guide covers everything you need to know to score full marks in your practical exam.
Practical Exam Structure
| Component | Marks | Details |
|---|---|---|
| Lab Work | 12 | Solve Python + SQL problems during the exam |
| Report File | 7 | Minimum 20 programs (Python + SQL) |
| Project | 8 | Python application with database connectivity |
| Viva Voce | 3 | Oral questions from the examiner |
| Total | 30 |
Part 1: Lab Work (12 marks)
During the exam, you will be given Python programming problems and SQL queries to solve on the computer.
What to Expect
You will typically get:
- 1-2 Python programs to write and execute, 2-3 SQL queries based on given tables, Time: Usually 2-3 hours for the complete practical
Python Programs to Practice
These are the most commonly asked program categories:
1. String Programs
# Count vowels and consonants in a string
def count_vc(text):
vowels = "aeiouAEIOU"
v_count = 0
c_count = 0
for ch in text:
if ch.isalpha():
if ch in vowels:
v_count += 1
else:
c_count += 1
return v_count, c_count
s = input("Enter a string: ")
v, c = count_vc(s)
print("Vowels:", v)
print("Consonants:", c)
Enter a string: Hello World
Vowels: 3
Consonants: 7
2. List/Tuple Programs
# Linear search in a list
def linear_search(lst, item):
for i in range(len(lst)):
if lst[i] == item:
return i
return -1
numbers = [10, 25, 30, 45, 50, 65, 70]
search = int(input("Enter number to search: "))
pos = linear_search(numbers, search)
if pos != -1:
print(f"Found at index {pos}")
else:
print("Not found")
Enter number to search: 45
Found at index 3
3. File Handling Programs
# Count words in a text file
def count_words(filename):
with open(filename, 'r') as f:
content = f.read()
words = content.split()
return len(words)
# First create a file
with open("sample.txt", 'w') as f:
f.write("Python is a great programming language.\n")
f.write("It is used for AI and web development.\n")
word_count = count_words("sample.txt")
print("Total words:", word_count)
Total words: 15
4. Stack Implementation
# Stack using list
stack = []
def push(item):
stack.append(item)
print(f"Pushed: {item}")
def pop():
if len(stack) == 0:
print("Stack Underflow!")
return None
return stack.pop()
def display():
if len(stack) == 0:
print("Stack is empty")
else:
print("Stack (top to bottom):", stack[::-1])
# Operations
push(10)
push(20)
push(30)
display()
print("Popped:", pop())
display()
Pushed: 10
Pushed: 20
Pushed: 30
Stack (top to bottom): [30, 20, 10]
Popped: 30
Stack (top to bottom): [20, 10]
5. Binary File Handling
import pickle
# Write student records to binary file
def write_records():
students = []
n = int(input("How many students? "))
for i in range(n):
roll = int(input("Roll No: "))
name = input("Name: ")
marks = float(input("Marks: "))
students.append({"roll": roll, "name": name, "marks": marks})
with open("students.dat", "wb") as f:
pickle.dump(students, f)
print("Records saved!")
# Read and display records
def read_records():
with open("students.dat", "rb") as f:
students = pickle.load(f)
for s in students:
print(f"Roll: {s['roll']}, Name: {s['name']}, Marks: {s['marks']}")
write_records()
read_records()
6. CSV File Handling
import csv
# Write to CSV
def write_csv():
with open("marks.csv", "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Name", "Maths", "Science"])
writer.writerow(["Aman", 85, 90])
writer.writerow(["Priya", 92, 88])
writer.writerow(["Rahul", 78, 82])
print("CSV file created!")
# Read from CSV
def read_csv():
with open("marks.csv", "r") as f:
reader = csv.reader(f)
for row in reader:
print(row)
write_csv()
read_csv()
CSV file created!
['Name', 'Maths', 'Science']
['Aman', '85', '90']
['Priya', '92', '88']
['Rahul', '78', '82']
SQL Queries to Practice
You will be given a table structure and asked to write queries. Here is a sample:
Given Table: EMPLOYEE
| EmpNo | Name | Dept | Salary | City |
|---|---|---|---|---|
| 101 | Aman | Sales | 45000 | Delhi |
| 102 | Priya | IT | 55000 | Mumbai |
| 103 | Rahul | Sales | 40000 | Delhi |
| 104 | Sneha | HR | 50000 | Kolkata |
| 105 | Vikram | IT | 60000 | Chennai |
Common queries asked in practical exams:
-- Display all records
SELECT * FROM EMPLOYEE;
-- Display names and salaries of IT department
SELECT Name, Salary FROM EMPLOYEE WHERE Dept = 'IT';
-- Display employees earning more than 45000
SELECT * FROM EMPLOYEE WHERE Salary > 45000;
-- Display total salary department-wise
SELECT Dept, SUM(Salary) AS TotalSalary
FROM EMPLOYEE GROUP BY Dept;
-- Display employees from Delhi or Mumbai
SELECT * FROM EMPLOYEE WHERE City IN ('Delhi', 'Mumbai');
-- Display count of employees in each city
SELECT City, COUNT(*) AS EmpCount
FROM EMPLOYEE GROUP BY City;
-- Display employees sorted by salary in descending order
SELECT * FROM EMPLOYEE ORDER BY Salary DESC;
-- Display the highest salary
SELECT MAX(Salary) AS MaxSalary FROM EMPLOYEE;
-- Display employees whose name starts with 'A'
SELECT * FROM EMPLOYEE WHERE Name LIKE 'A%';
-- Display departments having more than 1 employee
SELECT Dept, COUNT(*) FROM EMPLOYEE
GROUP BY Dept HAVING COUNT(*) > 1;
Part 2: Report File (7 marks)
Your report file must contain a minimum of 20 programs - a mix of Python programs and SQL queries.
Recommended Program List
Python Programs (at least 15):
- Programs using string functions (upper, lower, find, count)
- Program to count vowels, consonants, digits, and spaces in a string
- Program using lists (search, sort, frequency)
- Program to implement Stack using list
- Program to read and write text files
- Program to count specific words/characters in a text file
- Program to read and write binary files using pickle
- Program to search in a binary file
- Program to read and write CSV files
- Program using functions with different argument types
- Program using recursion (factorial, Fibonacci)
- Program to generate random numbers
- Program using dictionaries
- Program for Python-MySQL connectivity (INSERT, SELECT)
- Program for Python-MySQL connectivity (UPDATE, DELETE)
SQL Queries (at least 5):
- CREATE TABLE with constraints
- INSERT, UPDATE, DELETE operations
- SELECT with WHERE, ORDER BY
- Aggregate functions (SUM, AVG, COUNT, MAX, MIN) with GROUP BY
- Queries with HAVING, DISTINCT, BETWEEN, IN, LIKE
Report File Formatting Tips
- Write neatly - Use ruled paper or printed sheets
- Include for each program:
- Program number and title
- Aim/objective
- Source code
- Output/result
- Add an index page with program numbers and page numbers
- Get it signed by your teacher regularly
- Submit on time - Late submission may lose marks
Part 3: Project (8 marks)
What is Expected
A project that demonstrates:
- Python programming skills, Database connectivity (Python + MySQL), A real-world application
Good Project Ideas
| Project | Description |
|---|---|
| Library Management | Add books, issue/return, search, reports |
| Student Result System | Enter marks, calculate grades, generate report cards |
| Quiz Application | Multiple choice questions, scoring, result display |
| Inventory Management | Add products, track stock, generate bills |
| Contact Book | Add, search, update, delete contacts |
| Expense Tracker | Record expenses, view by category, monthly report |
| Hospital Management | Patient registration, appointment, billing |
Project Structure
Your project should have:
- Introduction - What problem does it solve?
- Hardware/Software requirements - Python 3.x, MySQL, etc.
- Source code - Well-commented, organized code
- Output screenshots - Show the program running
- Bibliography - Books and websites referenced
Sample Project Code (Student Result System)
import mysql.connector
def connect_db():
return mysql.connector.connect(
host="localhost",
user="root",
password="password",
database="school"
)
def add_student():
conn = connect_db()
cursor = conn.cursor()
roll = int(input("Enter Roll No: "))
name = input("Enter Name: ")
maths = int(input("Enter Maths marks: "))
science = int(input("Enter Science marks: "))
english = int(input("Enter English marks: "))
total = maths + science + english
avg = total / 3
sql = "INSERT INTO results VALUES (%s, %s, %s, %s, %s, %s, %s)"
cursor.execute(sql, (roll, name, maths, science, english, total, avg))
conn.commit()
print("Student added successfully!")
conn.close()
def view_all():
conn = connect_db()
cursor = conn.cursor()
cursor.execute("SELECT * FROM results")
records = cursor.fetchall()
print(f"{'Roll':<6} {'Name':<15} {'Maths':<7} {'Science':<9} {'English':<9} {'Total':<7} {'Avg':<6}")
print("-" * 60)
for row in records:
print(f"{row[0]:<6} {row[1]:<15} {row[2]:<7} {row[3]:<9} {row[4]:<9} {row[5]:<7} {row[6]:<6.1f}")
conn.close()
# Main menu
while True:
print("\n--- Student Result System ---")
print("1. Add Student")
print("2. View All Students")
print("3. Exit")
choice = int(input("Enter choice: "))
if choice == 1:
add_student()
elif choice == 2:
view_all()
elif choice == 3:
print("Goodbye!")
break
else:
print("Invalid choice!")
Part 4: Viva Voce (3 marks)
Common Viva Questions
Python:
- What is the difference between a list and a tuple?
- What is the use of the
picklemodule? - Explain the difference between text file and binary file.
- What is a stack? What are push and pop operations?
- What is the
globalkeyword used for? - What are the different file opening modes?
- What is exception handling? Name two exception types.
- What is the difference between
read(),readline(), andreadlines()? - What is recursion? Give an example.
- What is the difference between
==andisin Python?
SQL:
- What is the difference between DDL and DML?
- What is a primary key?
- What is the difference between WHERE and HAVING?
- Name five aggregate functions in SQL.
- What is the difference between DELETE and DROP?
- What is the purpose of GROUP BY?
- What does LIKE operator do? What are wildcards?
- What is a foreign key?
- What is the difference between CHAR and VARCHAR?
- What is the purpose of ORDER BY?
Python-MySQL:
- Which module is used for MySQL connectivity in Python?
- What is the purpose of
cursor()method? - What is the difference between
fetchone()andfetchall()? - Why do we use
commit()after INSERT/UPDATE/DELETE? - How do you handle database connection errors?
Viva Tips
- Know your project thoroughly - Be able to explain every line of code
- Understand, do not memorize - Examiners can tell if you are reciting
- Be confident - Speak clearly and make eye contact
- If you do not know, say so - Do not make up answers
- Review basics before the exam, data types, functions, SQL commands
Practical Exam Day Tips
- Arrive early and set up your computer
- Test Python and MySQL are working before you start
- Read the question paper carefully before typing
- Plan your logic on paper before coding
- Test your code with different inputs
- Save your work frequently - Do not risk losing it
- Comment your code - Shows the examiner you understand it
- Handle errors gracefully - Use try-except if needed
- Keep your report file ready with all signatures
- Be prepared for the viva - Review your project and key concepts
Quick Revision Checklist
Before the practical exam, make sure you can:
- Write Python programs for strings, lists, tuples, dictionaries
- Implement a stack using list (push, pop, display)
- Read and write text files, binary files, CSV files
- Write basic and advanced SQL queries
- Connect Python to MySQL and perform CRUD operations
- Explain your project code line by line
- Answer common viva questions
- Your report file is complete with all 20+ programs
- Your project is complete with documentation
Want to learn more?
Explore free chapter-wise notes with quizzes and code playground
Prefer watching over reading?
Subscribe for free.