Cual es el fallo aqui?


#1



https://www.codecademy.com/es/courses/python-beginner-es-xxvnq/1/6?curriculum_id=53a32847fed2a88075000001#


No se cual es el fallo. Según la consola es fallo de .append. Este es el mensaje de error:
Traceback (most recent call last):
File "python", line 6, in
AttributeError: 'int' object has no attribute 'append'


lista_inicial = [5, 3, 1, 2, 4]
lista_cuadrado = []

# Tu código va acá
for lista_cuadrado in lista_inicial:
    lista_cuadrado.append(lista_inicial ** 2)
lista_cuadrado.sort()
print lista_cuadrado


#2

I guess the problem is that you use the same name on multiple occasions:

lista_cuadrado = []

and

for lista_cuadrado in lista_inicial:

The first one is a list which has an .append() attribute. But the second one is just an element of the lista_inicial so for example an integer (int) value of 5 (first value of this list) and of course you cannot append a number to a number.

So for example just go with:

lista_inicial = [5, 3, 1, 2, 4]
lista_cuadrado = []

# Tu código va acá
for elemento_de_la_lista in lista_inicial:
    lista_cuadrado.append(elemento_de_la_lista ** 2)
lista_cuadrado.sort()
print lista_cuadrado

Btw: As you can see the other problem was that you squared the whole list here:

lista_cuadrado.append(lista_inicial ** 2)

Whereas you just need to square and append one element at a time.

Hope this helps.