[Tutor] Beginner - understanding randint arguments
Jay Lozier
jslozier at gmail.com
Sat Feb 15 19:47:16 CET 2014
On 02/15/2014 11:25 AM, Marc Eymard wrote:
> Hello Tutor,
>
> I need to generate a random integer between 0 and 100.
>
> The range is supposed to be adjusted by my two variables:
> low_range and high_range.
>
> The logic of using the variables as part of the function arguments is
> to manage to get a smaller range each time the function is called
> _excluding_ the possible repeat of the return value of randint.
>
> Here is what happens in my script:
>
> >>> import random
> >>> low_range = -1
> >>> high_range = 101
> >>> random.randint(low_range + 1, high_range - 1)
> 56
> >>> low_range
> -1
> >>> high_range
> 101*
> *
>
>
> I was rather expecting:
>
> >>> low_range
>
> 0
>
> >>> high_range
>
> 100
>
>
> Can somebody explain why both low_range and high_range are still
> returning their initial values ?
>
> Thanks,
> Marc*
> *
The variables low_range and high_range are not modified. The arguments
to random.randint do not change the initial values of the variables,
only the actual values passed.
--
Jay Lozier
jslozier at gmail.com
More information about the Tutor
mailing list