What minimum and maximum values will be generated for the following Python…
2023
What minimum and maximum values will be generated for the following Python statement? print(random.randrange(100) + 1)
- A.
1 and 100
- B.
0 and 100
- C.
1 and 99
- D.
0 and 99
Attempted by 1793 students.
Show answer & explanation
Correct answer: A
The function random.randrange(100) generates integers from 0 to 99, inclusive. Adding 1 to each value shifts the entire range upward by one unit. Therefore, the minimum value becomes 0 + 1 = 1, and the maximum value becomes 99 + 1 = 100. The resulting range is 1 to 100, inclusive.