Advertisements
Advertisements
प्रश्न
What possible output(s) from the given options will NOT be displayed when the following code is executed? Also, mention, for how many iterations the for loop in the given code will run?
import random
a = [1, 2, 3, 4, 5, 6]
for i in range (4) :
j = random.randrange (i, 5)
print(a[j],end='-')
print()
विकल्प
3−4−5−4−
2−2−4−5−
4−3−3−5−
5−1−2−4−
MCQ
Advertisements
उत्तर
5−1−2−4−
Explanation:
random.randrange(i,5) yields j in [i..4], so the second iteration (i=1) can only pick indices ≥1, it cannot produce index 0, therefore the sequence containing "1" in the second position (5-1-2-4-) is impossible.
shaalaa.com
क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2025-2026 (March) Set 4
