To do it the way you're trying to do it, use this:
>>> num = 0
>>> mylist = []
>>>
>>> while num < 10:
... num += 1
... mylist += [num]
...
>>> for item in mylist:
... print item
...
1
2
3
4
5
6
7
8
9
10
>>>
Notice I put brackets around
num since you have to add a list to a list when using the + operator. Other methods would be to use
mylist.append(num) or
mylist.insert(index, num) . I also changed your
x = x + y statements to
x += y , which is identical.
HTH
Last edited by jlm699; Oct 19th, 2009 at 6:56 pm.
Reputation Points: 355
Solved Threads: 292
Veteran Poster
Offline 1,102 posts
since Jul 2008