[Tutor] Random Number Game: Returns always the same number - why?

Thomas Murphy thomasmurphymusic at gmail.com
Mon May 20 18:55:02 CEST 2013


Mitya,
Why is it best in this situation to use range() rather than a while
loop? Curious about best practices for the various iterating
functions. Thanks!


> There are a few issues here:
> * variable names should be lower case
> * for this case it's best to use for loop with range()
> * you calculate random number only once, outside of loop
>
> Try something like:
>
> for count in range(100):
> print random.randint(1, 100)
>
>
> -m


More information about the Tutor mailing list