On Sun, Dec 22, 2013 at 3:55 AM, <tutor-requ...@python.org> wrote:

> import random
>
> for i in range(1):
>     RN1 = random.randint(1,75)
>

As noted before, these "for i in range(1)" statements are pointless:
iteration over a range of 1 is no iteration at all. This is exactly
equivalent to simply saying

    RN1 = random.randint(1,75)

One thing you might want to do is carefully document your code: add a bunch
of lines, preceded by the pound sign # (to make them into comments), to
explain what you're trying to do in the next section. This might help you
clarify your thinking, and it will definitely help others understand your
intention. Like this:

# Collect a set of lottery results
RN1 = random.randint(1, 75)
RN2 = random.randint(1, 75)
etc.

You could do this entire piece with a list comprehension in one line, but
I'm only mentioning it b/c I just learned them. My crude first effort would
look like this:

RN = []  # create the array RN
[RN.append(random.randint(1, 75)) for i in range(5)]  # populate the array

Also, the fact that you have an identical set of assignments twice makes
one wonder if it's time for a function...

Mostly though, add comments!
-- 
Keith
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to