Practical file, project and viva

Part of the free LogicWiz Python course, Pack A: CBSE Class 12 Board Pack. The examples and practice run in the app.

Your practical is 30 marks: lab test 12, report file 7, project 8, viva 3. That is almost half a theory paper, and you can secure most of it before March by preparing the programs and the project now.

You'll learn to

  • Know what the report file, lab test and project must contain
  • Have tested model programs for the CBSE practical list
  • Plan a project: a GST invoice generator or a quiz game
  • Answer the viva questions examiners ask most

Learn

What the 30 marks need

Part Marks What you do
Lab test 8 + 4 One Python program, and 4 SQL queries on one or two tables
Report file 7 At least 15 Python programs, 5 sets of SQL queries, 4 Python-SQL connectivity programs
Project 8 A group of 2-3 builds a real app with file handling or Python-SQL
Viva 3 Questions on your programs and project

The Python program in the lab test is marked 60% logic, 20% documentation (comments), 20% code quality.

Three text-file programs from the practical list

# 1. Display each word of the file separated by #
with open("story.txt") as f:
    for line in f:
        print("#".join(line.split()))

# 2. Count vowels, consonants, uppercase and lowercase letters
v = c = up = low = 0
with open("story.txt") as f:
    text = f.read()
for ch in text:
    if ch.isalpha():
        if ch in "aeiouAEIOU":
            v += 1
        else:
            c += 1
        if ch.isupper():
            up += 1
        else:
            low += 1
print("Vowels:", v, "Consonants:", c, "Upper:", up, "Lower:", low)

# 3. Copy the lines that do not contain 'a' into another file
with open("story.txt") as src, open("no_a.txt", "w") as dst:
    for line in src:
        if "a" not in line:
            dst.write(line)
print(open("no_a.txt").read())

The other practical-list programs are in this pack: binary search and update (A1-A2), CSV user-id/password (A3), stack (A4), SQL sets (A5) and Python-SQL (A6).

Dice simulator

import random

def roll_dice():
    """Return a random number from 1 to 6, like a dice."""
    return random.randint(1, 6)

for player in ["Aarav", "Meher", "Kabir"]:
    print(player, "rolled", roll_dice())

Run it again: the numbers change. That's the point. A docstring and clear names earn the documentation marks.

Project template 1: GST invoice generator

import csv, pickle

GST = {"food": 5, "stationery": 12, "electronics": 18}   # rate in %
sales = [
    ("Parle-G biscuits", "food", 10, 10.0),
    ("Notebook", "stationery", 4, 45.0),
    ("Earphones", "electronics", 1, 499.0),
    ("Toor dal 1kg", "food", 2, 160.0),
]

def make_invoice(no, customer, lines):
    by_rate = {}                                  # group taxable value by GST rate
    print("TAX INVOICE No.", no, "-", customer)
    for name, cat, qty, price in lines:
        value = qty * price
        rate = GST[cat]
        by_rate[rate] = by_rate.get(rate, 0) + value
        print(f"{name:<18}{qty:>3} x {price:>7.2f} = {value:>8.2f}  GST {rate}%")
    tax = 0
    for rate in sorted(by_rate):
        t = round(by_rate[rate] * rate / 100, 2)
        tax += t
        print(f"Taxable at {rate:>2}%: {by_rate[rate]:>8.2f}  CGST {t/2:.2f}  SGST {t/2:.2f}")
    taxable = sum(by_rate.values())
    grand = round(taxable + tax, 2)
    print(f"Grand total: Rs {grand:.2f}")
    return [no, customer, taxable, round(tax, 2), grand]

row = make_invoice(1, "Sharma Kirana", sales)
with open("invoices.csv", "a", newline="") as f:          # summary for Excel
    csv.writer(f).writerow(row)
with open("invoices.dat", "ab") as f:                    # full invoice for reprinting
    pickle.dump({"no": 1, "customer": "Sharma Kirana", "lines": sales}, f)
print("Saved to invoices.csv and invoices.dat")

This is CBSE's own example idea: take a shop's transactions, group them by GST rate, and print a proper invoice. Grow it with a menu: new invoice, reprint by number (search the .dat), monthly GST report (read the CSV).

Project template 2: quiz game

import pickle

questions = [
    ("Which pickle method writes an object to a file?", "dump"),
    ("Which SQL clause filters groups?", "having"),
    ("Which list method pushes onto a stack?", "append"),
]
with open("quiz.dat", "wb") as f:
    for q in questions:
        pickle.dump(q, f)

def play(name):
    score = 0
    with open("quiz.dat", "rb") as f:
        try:
            while True:
                q, ans = pickle.load(f)
                reply = input(q + " ")
                if reply.strip().lower() == ans:
                    print("Correct!")
                    score += 1
                else:
                    print("Wrong. Answer:", ans)
        except EOFError:
            pass
    print(name, "scored", score, "out of", len(questions))

play(input("Your name: "))

Grow it with: questions added by a teacher menu, a high-score table in a CSV, random order with random.shuffle, or a MySQL table of questions.

The project file

Your project report usually has: certificate, acknowledgement, introduction (the problem and who it helps), hardware and software used, modules and functions used, the data design (file or table structure), the full source code, sample output, limitations and future scope, and bibliography.

CBSE says: start at least 6 months before the deadline, work in a group of 2-3, solve a real problem (visit a local shop and ask what is hard for them), and never copy code you cannot explain.

Viva survival: the examiner picks a line of your code and asks "why this?". Be ready to explain every mode (rb, ab, newline=""), every try/except, why you commit(), and what each function returns. If you don't know, say what you would check. Never bluff.

Lab-test habits that earn the 40% beyond logic: a comment at the top (aim of the program), a docstring per function, meaningful names (total_marks, not t), clear prompts for input(), output with labels, and one test run with sample data written in the file.

In one line

Practical = lab test 12 + report file 7 + project 8 + viva 3; keep tested, commented programs for every practical-list item and be able to explain each line.