मराठी

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? - Computer Science (Python)

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
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×