Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2026 Crash Course
NEET 2026 Crash Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
70 views
in Computer by (40 points)
What possible output(s) are expected to be displayed on screen at the time of execution of the following code? Also specify the maximum and minimum value that can be assigned to variable X.
import random
L=[10,7,21]
2 X=random.randint(1,2)
for i in range(X):
Y=random.randint(1,X)
print(L[Y],"$",end="")
(a) 10 $7$
(b) 21 $7$
(c) 21 $ 10 $
(d) 7 $

Please log in or register to answer this question.

1 Answer

0 votes
by (28.4k points)

The list L = [10, 7, 21] has these values at these positions:

  • L[0] = 10

  • L[1] = 7

  • L[2] = 21

X = random.randint(1,2) means X can be 1 or 2.

The loop runs X times, and each time it picks Y = random.randint(1, X).

  • If X = 1, Y is always 1 → Prints 7 $

  • If X = 2, Y can be 1 or 2, so different outputs are possible:

    • 7 $ 7 $

    • 7 $ 21 $

    • 21 $ 7 $

    • 21 $ 21 $

Matching with options:

(b) 21 $ 7 $ (Possible when X=2, Y=2,1)

(d) 7 $ (Possible when X=1)

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...