Correct option is C
The Python
random.randrange() function generates a random number from the specified range. The syntax is:
random.randrange(stop)
This will generate a random integer from 0 to stop - 1 (i.e., from 0 to 99 for stop = 100).
The given code:
print(random.randrange(100) + 1)
1.
random.randrange(100) generates a random number between
0 and 99.
2. The + 1 adds 1 to this random number, which will shift the range to
1 and 100.
Thus, the minimum value generated will be
1, and the maximum value generated will be
100.
Important Key Points:
1.
randrange(stop): Generates a random number from 0 to stop - 1.
2.
+ 1: This shifts the entire range by 1, so the new range becomes
1 to 100.
Knowledge Booster:
·
Option (a): This is incorrect because the
maximum value is 100, not 100+1.
·
Option (b): This is incorrect because
0 is included in the randrange(100) function output before adding 1.
·
Option (d): This is incorrect because
random.randrange(100) will give a value between
0 and 99 (before adding 1), and with + 1, the range shifts to 1 to 100, not 0 to 99.