Skip to content
Question 82 of 97

Q.What possible output(s) are expected to be displayed on screen at the time of execution of the program from the following code? Also specify the minimum and maximum values that can be assigned to the variable End. import random Colours = ["VIOLET","INDIGO","BLUE","GREEN","YELLOW","ORANGE","RED"] End = randrange(2)+3 Begin = randrange(End)+1 for i in range(Begin,End): print(Colours[i],end="&")

(i) INDIGO&BLUE&GREEN&
(ii) VIOLET&INDIGO&BLUE&
(iii) BLUE&GREEN&YELLOW&
(iv) GREEN&YELLOW&ORANGE&
Odisha ChseCBSE Class XII Board 2020Subjective· 2mImportance★★★★★
85% · 82/97 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

End = randrange(2)+3 can only be 3 or 4, and Begin = randrange(End)+1 is always at least 1 — so the printed slice never starts at index 0 and never goes past index 3. Only option (i) INDIGO&BLUE&GREEN& is possible; minimum End = 3, maximum End = 4.

Concept — what randrange can produce

random.randrange(n) returns a random integer from 0 up to n-1 (the stop value is excluded). Applying that to each line (the paper writes randrange(...) after import random; per the CBSE marking convention it is evaluated as random.randrange(...)):

import random
Colours = ["VIOLET","INDIGO","BLUE","GREEN","YELLOW","ORANGE","RED"]
End = random.randrange(2)+3      # randrange(2) is 0 or 1  ->  End is 3 or 4
Begin = random.randrange(End)+1  # randrange(End) is 0..End-1  ->  Begin is 1..End
for i in range(Begin,End):
    print(Colours[i],end="&")
  • End: randrange(2) gives 0 or 1, so End is 3 or 4.
  • Begin: randrange(End) gives 0 … End-1, so Begin is 1 … End — never 0.
  • The loop range(Begin, End) prints Colours[i] for i = Begin … End-1, each followed by &.

Index map of the list:

Index0123456
ColourVIOLETINDIGOBLUEGREENYELLOWORANGERED

Exhaustive trace — every possible run

EndBeginIndices printedOutput
311, 2INDIGO&BLUE&
322BLUE&
33none(empty line)
411, 2, 3INDIGO&BLUE&GREEN&
422, 3BLUE&GREEN&

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.