gherron at digipen.edu
Mon Oct 11 18:55:23 CEST 2010
On 10/11/2010 09:24 AM, Fasihul Kabir wrote:
> a = *5
> for i in range(0, 4):
> for j in range(0, i):
> why the above codes show the following error. and how to overcome it.
> Traceback (most recent call last):
> File "<pyshell#10>", line 3, in <module>
> AttributeError: 'int' object has no attribute 'append'
Well.... What are you trying to do with the append? If you are trying
to grow the list "a" beyond the original 5 zeros you put into it, then
If you are trying to build a list from the two loops, then don't
pre-fill "a". Rather start with an empty list
a = 
and append to it
Don't know what you want, but there is usually not a need to pre-fill an
array like this: a=*5 . That looks more like declaring an array as
in C or C++ or many other languages. And I don't understand the the "5"
in that. Looking at your loops, I see that 6 passs through the inner
loop are produced:
for i in range(0, 4):
for j in range(0, i):
In any case.
Your "a" is a list, containing integers.
a[i] indexes the list to produce an integer
a[i].append(...) attempts to append something to an integer -- an
operation that makes no sense.
Gary Herron, PhD.
Department of Computer Science
DigiPen Institute of Technology
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list