Consider the given Python programme and identify one possible output of this…

2023

Consider the given Python programme and identify one possible output of this code out of the following options : from random import * Low = randint(2, 3) High = randrange(5, 7) for N in range(Low, High): print(N, end=' ')

  1. A.

    3 4 5

  2. B.

    2 3

  3. C.

    4 5

  4. D.

    3 4 5 6

Attempted by 1446 students.

Show answer & explanation

Correct answer: A

Answer: 3 4 5

Reason:

  • Low is chosen by randint(2,3), so Low can be 2 or 3.

  • High is chosen by randrange(5,7), so High can be 5 or 6.

  • range(Low, High) prints integers from Low up to High - 1 (High is excluded).

  • Possible (Low, High) combinations and their outputs:

    • Low=2, High=5 -> 2 3 4

    • Low=2, High=6 -> 2 3 4 5

    • Low=3, High=5 -> 3 4

    • Low=3, High=6 -> 3 4 5

Therefore, 3 4 5 is a valid possible output (when Low = 3 and High = 6).

Explore the full course: Rssb Senior Computer Instructor