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):

  1. Programs using string functions (upper, lower, find, count)
  2. Program to count vowels, consonants, digits, and spaces in a string
  3. Program using lists (search, sort, frequency)
  4. Program to implement Stack using list
  5. Program to read and write text files
  6. Program to count specific words/characters in a text file
  7. Program to read and write binary files using pickle
  8. Program to search in a binary file
  9. Program to read and write CSV files
  10. Program using functions with different argument types
  11. Program using recursion (factorial, Fibonacci)
  12. Program to generate random numbers
  13. Program using dictionaries
  14. Program for Python-MySQL connectivity (INSERT, SELECT)
  15. Program for Python-MySQL connectivity (UPDATE, DELETE)

SQL Queries (at least 5):

  1. CREATE TABLE with constraints
  2. INSERT, UPDATE, DELETE operations
  3. SELECT with WHERE, ORDER BY
  4. Aggregate functions (SUM, AVG, COUNT, MAX, MIN) with GROUP BY
  5. Queries with HAVING, DISTINCT, BETWEEN, IN, LIKE

Report File Formatting Tips

  1. Write neatly - Use ruled paper or printed sheets
  2. Include for each program:
    • Program number and title
    • Aim/objective
    • Source code
    • Output/result
  3. Add an index page with program numbers and page numbers
  4. Get it signed by your teacher regularly
  5. 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:

  1. Introduction - What problem does it solve?
  2. Hardware/Software requirements - Python 3.x, MySQL, etc.
  3. Source code - Well-commented, organized code
  4. Output screenshots - Show the program running
  5. 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:

  1. What is the difference between a list and a tuple?
  2. What is the use of the pickle module?
  3. Explain the difference between text file and binary file.
  4. What is a stack? What are push and pop operations?
  5. What is the global keyword used for?
  6. What are the different file opening modes?
  7. What is exception handling? Name two exception types.
  8. What is the difference between read(), readline(), and readlines()?
  9. What is recursion? Give an example.
  10. What is the difference between == and is in Python?

SQL:

  1. What is the difference between DDL and DML?
  2. What is a primary key?
  3. What is the difference between WHERE and HAVING?
  4. Name five aggregate functions in SQL.
  5. What is the difference between DELETE and DROP?
  6. What is the purpose of GROUP BY?
  7. What does LIKE operator do? What are wildcards?
  8. What is a foreign key?
  9. What is the difference between CHAR and VARCHAR?
  10. What is the purpose of ORDER BY?

Python-MySQL:

  1. Which module is used for MySQL connectivity in Python?
  2. What is the purpose of cursor() method?
  3. What is the difference between fetchone() and fetchall()?
  4. Why do we use commit() after INSERT/UPDATE/DELETE?
  5. How do you handle database connection errors?

Viva Tips

  1. Know your project thoroughly - Be able to explain every line of code
  2. Understand, do not memorize - Examiners can tell if you are reciting
  3. Be confident - Speak clearly and make eye contact
  4. If you do not know, say so - Do not make up answers
  5. Review basics before the exam, data types, functions, SQL commands

Practical Exam Day Tips

  1. Arrive early and set up your computer
  2. Test Python and MySQL are working before you start
  3. Read the question paper carefully before typing
  4. Plan your logic on paper before coding
  5. Test your code with different inputs
  6. Save your work frequently - Do not risk losing it
  7. Comment your code - Shows the examiner you understand it
  8. Handle errors gracefully - Use try-except if needed
  9. Keep your report file ready with all signatures
  10. 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.

Subscribe on YouTube