[Tutor] help with random.randint
David
ldl08 at gmx.net
Wed Feb 3 12:26:43 CET 2010
Hello Eike,
thanks for the explanation, all this is really helpful -- I certainly
have learned sth. today!
I wonder, though, how I would get my number pairs, which I need later
on, if I were to follow your solution. I am asking because as I
understand your code, the list terms is a list of integers here, but not
of x,y pairs, right? (I can see that this was a problem of my code right
from the start, btw.)
David
On 03/02/10 19:08, Eike Welk wrote:
> Hello David!
>
> On Wednesday February 3 2010 04:21:56 David wrote:
>>
>> import random
>> terms = []
>> for i in range(2):
>> terms = random.randint(1, 99)
>> print terms
>
> Here is an other solution, which is quite easy to understand and short:
>
> import random
> terms = []
> for i in range(2):
> terms += [random.randint(1, 99)]
> print terms
>
>
> Note the rectangular brackets around "[random.randint(1, 99)]". This creates a
> list which a single number in it. This small list can then be added to the
> already existing list "terms".
>
>
> Eike.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list