CBSE Class 12 Computer Science: Important Output Questions, Solved
By Subhanu Sankar Roy · · 3 min read
Output questions ask what a short Python program prints. They appear in every CBSE Class 12 Computer Science paper, and they are where well-prepared students quietly lose marks. The fix is a habit, not talent: trace the code line by line on paper before writing an answer. Below are solved examples of the types that come up most, each with the reasoning.
How to trace code (the method)
Draw one column per variable. Go through the code one line at a time and write each new value under its variable. When something is printed, write it down exactly, including spaces, brackets and quotes. Only then write the answer. It feels slow at first, and it stops being slow after about two weeks of daily practice.
1. String slicing
s = "BoardExam2026"
print(s[2:7])
print(s[::-2])
print(s[-4:])Output:
ardEx
60mxdaB
2026Number the characters first: B is index 0 and the final 6 is index 12. s[2:7] takes indices 2 to 6, so the stop index is never included. s[::-2] starts at the end and takes every second character backwards: indices 12, 10, 8, 6, 4, 2, 0.
2. Lists and aliasing
L = [1, 2, 3]
M = L
M.append(4)
L = L + [5]
print(L, M)Output:
[1, 2, 3, 4, 5] [1, 2, 3, 4]M = L does not copy the list; both names point to the same list, so append(4) changes both. But L + [5] builds a new list and points L at it, so M keeps the old one. This is one of the most commonly missed ideas in the paper.
3. Local and global variables
x = 10
def change(x):
x = x + 5
return x
def change_global():
global x
x = x * 2
print(change(x), x)
change_global()
print(x)Output:
15 10
20Inside change(), x is a parameter, a separate local variable, so the global x stays 10. change_global() declares x as global, so it doubles the real one.
4. Number reversal with a while loop
n = 1234
r = 0
while n > 0:
r = r * 10 + n % 10
n = n // 10
print(r)Trace:
- Start: n = 1234, r = 0
- After pass 1: r = 4, n = 123
- After pass 2: r = 43, n = 12
- After pass 3: r = 432, n = 1
- After pass 4: r = 4321, n = 0
Output: 4321. Know the difference between / (gives a float) and // (floor division).
5. Dictionaries
marks = {"Asha": 78, "Ravi": 91, "Meera": 85}
total = 0
for name in marks:
if marks[name] > 80:
total += marks[name]
print(total)Output: 176. Looping over a dictionary gives its keys, so marks[name] is needed to get each value. Ravi (91) and Meera (85) pass the condition.
6. Exception handling
try:
x = int("12a")
print("Converted")
except ValueError:
print("Not a number")
finally:
print("Done")Output:
Not a number
DoneThe error happens on the int() line, so "Converted" is never printed. finally runs whether or not an error happened.
7. Find the error
def total(a, b=0, c):
return a + b + cThis is a SyntaxError: a parameter without a default value cannot come after one with a default. Two correct fixes are def total(a, c, b=0) or def total(a, b=0, c=0).
Where students lose marks
- Writing the right values in the wrong format: missing brackets around a list, or quotes printed around a string.
- Forgetting that print() with several values puts a space between them.
- Treating M = L as a copy.
- Mixing up / and //, or forgetting that range() stops before its end value.
How to practise
Ten minutes a day is enough: take two output questions from a sample paper, trace them on paper, then run the code to check. Keep a notebook of the ones you got wrong and why. That notebook becomes your best revision material before the board exam.