[Tutor] help with random.randint
Eike Welk
eike.welk at gmx.net
Wed Feb 3 12:08:56 CET 2010
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.
More information about the Tutor
mailing list