CBSE · 083Class XII · 2023Section D2 marks
Question 32(1)
30 March 2023 · Computer Science (083)
What possible output(s) are expected to be displayed on screen at the time of execution of the following program ?
python
import random
M = [5, 10, 15, 20, 25, 30]
for i in range(1, 3):
first = random.randint(2, 5) - 1
sec = random.randint(3, 6) - 2
third = random.randint(1, 4)
print(M[first], M[sec], M[third], sep="#")Answer
(a) 10#25#15 20#25#25
Explanation
random.randint(2,5)-1 yields indices in {1,2,3,4}; random.randint(3,6)-2 yields {1,2,3,4}; random.randint(1,4) yields {1,2,3,4}. All three subscripts are always valid (1..4) and the separator '#' has no trailing '#' at the end of each line. Only option (a) satisfies these constraints on both iterations.