On 05/20/2013 12:55 PM, Thomas Murphy wrote:
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

It's a simpler and more idiomatic approach, as you can
see, you don't need to initialize the counter and you don't
need to manually increment it.  -m


--
Lark's Tongue Guide to Python: http://lightbird.net/larks/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to