What you'll learn
Quick Answer
Expect a file handling or data structure program, plus SQL. In the viva you will be asked to explain your own code line by line, so write programs you understand rather than the shortest version you can remember. Saying you do not know beats guessing confidently.
What the practical actually consists of
The exact split varies by school, but the shape is consistent: a Python program, some SQL, your project, the practical file, and a viva. The programs are drawn from a small pool, and almost all of them are variations on three themes — read a file and count something, implement a stack or queue on a list, or manipulate a dictionary.
The most useful preparation is therefore not breadth. It is being able to write those three from memory, correctly, and explain every line.
File handling: counting things
Some version of this appears almost every year. Given a text file, count characters, occurrences of a letter, or uppercase letters:
with open("viva.txt") as f:
data = f.read()
print(len(data)) # 55
print(data.count("e")) # 10
print(sum(1 for ch in data if ch.isupper())) # 2
Points that cost marks. read() returns the whole file as one string including newline characters, so a character count includes them — if the expected answer differs by the number of lines, that is why. count() is case-sensitive, so counting "e" does not include "E". And using with open(...) closes the file automatically, which examiners look for; opening without closing is a standard deduction.
Know the three modes cold: "r" read, "w" write which erases the existing file, and "a" append. Accidentally opening in "w" when you meant "a" destroys the data, and it is a favourite viva question precisely because it is destructive.
Stack and queue on a list
Both are implemented on a plain list, and the examiner will ask you which end each one operates on.
queue = []
queue.append(10); queue.append(20); queue.append(30)
print(queue) # [10, 20, 30]
front = queue.pop(0) # remove from the FRONT
print(front) # 10
print(queue) # [20, 30]
A queue is first-in first-out, so pop(0) takes the earliest item. A stack is last-in first-out and uses pop() with no argument, taking the most recent. Mixing these up under pressure is common; the fix is to say the full name to yourself — "first in, first out" — before writing the line.
Always check for empty before popping, and return a message rather than letting it crash. An IndexError during a practical looks much worse than an "Underflow" string.
Dictionaries: the frequency count
Counting word or character frequency is the most-asked dictionary program:
words = "the quick the lazy the dog".split()
freq = {}
for w in words:
freq[w] = freq.get(w, 0) + 1
print(freq) # {'the': 3, 'quick': 1, 'lazy': 1, 'dog': 1}
get(w, 0) returns 0 when the key is not yet present, which avoids a KeyError on the first occurrence of each word. Writing freq[w] = freq[w] + 1 directly crashes on the first word, and explaining why get is used is a very likely viva question.
Also be ready for string reversal, which has a one-line answer:
s = "python"
print(s[::-1]) # nohtyp
Be prepared to explain the slice: start and stop omitted means the whole string, and a step of -1 means walk backwards.
The viva: they are testing whether you wrote it
Viva questions are mostly about the code in front of you. Typical ones, all of which have short answers:
- Why did you use
with open()instead ofopen()? Because it closes the file automatically, even if an error occurs. - What is the difference between
readline()andreadlines()? One returns the next single line as a string; the other returns every line as a list. - What happens if you open a file in
"w"mode that already has data? It is erased. - What is the difference between a list and a tuple? A list is mutable, a tuple is not.
- What does
DISTINCTdo in SQL? Removes duplicate values from the result. - What is a primary key? A column whose value uniquely identifies each row and cannot be NULL.
Two pieces of advice that matter more than any individual answer. First, if you do not know, say so — examiners ask follow-ups, and a confident wrong answer invites three more questions on the same topic. Second, never submit a program you cannot explain line by line, however impressive it looks. Being unable to explain your own submitted code is the single worst outcome in a viva.
The practical file and the project
Write the practical file as you go rather than in the last week. Each program needs the code, sample input and the actual output — and the output must be what the program really prints, not what you think it prints. Examiners do check, and a mismatch raises the question of whether you ran it at all.
For the project, the same rule as the viva applies: know every part of it. If it was a group project, be able to explain the parts you did not write as well, because you will be asked.
For the theory side of the syllabus, our free Class 12 Computer Science chapters cover it with worked answers, and the board exam preparation guide covers the written paper.
