On this page
"What possible output is expected to be displayed on the screen?" is a one-mark question that appears in CBSE computer science papers, and it catches students who know Python well. The program uses the random module, so you cannot just trace it once. You have to trace it for every value the random calls could return. This post gives a method that turns the question into a short table, works the official sample paper question, then a second one, and lists the traps.
Where does the random module appear in the syllabus?
The CBSE Computer Science curriculum for 2026-27 lists the random module, with random(), randint() and randrange(), under Python modules in Class 11. The Class 12 syllabus starts with a revision of Class 11 Python topics, and the Class 12 practical list includes a random number generator that simulates a dice. The Class 12 sample question paper for 2026-27 uses randint() and randrange() in Question 6. Check the curriculum for your year.
What exactly do the three functions return?
From the Python documentation for the random module:
random() returns a floating-point number X with 0.0 <= X < 1.0. It can be 0.0 but never 1.0.
randint(a, b) returns an integer N with a <= N <= b. Both ends are included; the docs call it an alias for randrange(a, b+1).
randrange(start, stop) returns a randomly selected element from range(start, stop). Like range(), it never returns stop.
So randint(1, 3) can give 1, 2 or 3, but randrange(1, 3) can give only 1 or 2. Many wrong answers in these questions come from that one difference.
Worked example 1: the 2026-27 sample paper
import random
games = {0: "Chess", 1: "Scrabble", 2: "Sudoku", 3: "Tic-Tac-Toe", 4: "Puzzle"}
start_key = random.randint(1, 2)
end_key = random.randrange(3, 4)
for k in range(start_key, end_key + 1):
print(games[k], end="@@")Sets. start_key is in {1, 2}. end_key is randrange(3, 4), which can only be 3.
Loop range. range(start_key, 4), so k runs from start_key to 3.
Cases. If start_key = 1: Scrabble@@Sudoku@@Tic-Tac-Toe@@. If start_key = 2: Sudoku@@Tic-Tac-Toe@@.
Compare. Of the four options, only (b) Scrabble@@Sudoku@@Tic-Tac-Toe@@ matches a case. Chess (key 0) and Puzzle (key 4) can never print.
The official marking scheme gives (b).
Worked example 2: a case that prints nothing
import random
colours = ["RED", "GREEN", "BLUE", "PINK", "GOLD"]
low = random.randint(1, 3)
high = random.randrange(2, 4)
for i in range(low, high + 1):
print(colours[i], end="#")Which of these is a possible output? (a) GREEN#BLUE#PINK# (b) RED#GREEN#BLUE# (c) BLUE#PINK#GOLD# (d) PINK#BLUE#
Sets. low is in {1, 2, 3}; high is in {2, 3}, giving six cases:
low 1, high 2: GREEN#BLUE#
low 1, high 3: GREEN#BLUE#PINK#
low 2, high 2: BLUE#
low 2, high 3: BLUE#PINK#
low 3, high 2: nothing, because range(3, 3) is empty
low 3, high 3: PINK#
Check options. (a) matches low 1, high 3. (b) needs index 0, but low is at least 1. (c) needs index 4, but high is at most 3. (d) prints in decreasing order, which a forward range never does.
Answer: (a). A follow-up question might ask for the largest values low and high can take: both are 3.
Which traps should you check every time?
randrange's stop. randrange(3, 4) is always 3, not 3 or 4.
range()'s stop inside the loop. The loop above uses high + 1, so the last index printed is high itself.
Order. A forward loop prints in increasing index order. Any option that goes backwards is out.
Empty loops. If start can exceed stop, one case prints nothing.
Index range. An option that needs an index outside the possible set cannot occur.
Expressions with random(). int(random.random() * 6) + 1 gives 1 to 6, because random() * 6 is at least 0 and below 6.
For a full practical-file program, write the dice simulator from the CBSE list with randint(1, 6) and run it many times, noting which faces appear. For more tracing practice, see our posts on functions in Python for CBSE and the CBSE computer science practical file. When a trace goes wrong and you cannot see where, the Fermi Problem Library has a step-by-step solver that explains the reasoning rather than printing an answer.
A 15-minute practice routine
Write three short programs that each use randint() and randrange() together.
For each, write the value sets, then a table of every case and its output.
Write four options for each program, only one possible, and swap with a friend.
Run each program several times in Python to confirm your table, never to replace it.
Before your next test, redo sample-paper Question 6 from a blank page, writing the sets before you trace.



