9 more with for


#1

Good morning everyone.
I don't know how to append correctly.
https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/1/6?curriculum_id=4f89dab3d788890003000096

start_list = [5, 3, 1, 2, 4]
square_list = []
square_list.append(start_list[0:5])
print square_list

When I submit code I get this [[5, 3, 1, 2, 4]] instead of this [5,3,1,2,4]


#2

it says write a for loop, so you need for loop. Do you understand what for loops does?


#3

First, thanks for the quick reply.

Yes, I do. I already past the exercise.
but I can't understand why it gives me the double [[ instead of just one [.
I would like to fix it in order to use in future applications.

:slight_smile: Good day !


#4

because you are appending whole list, everything, for loop iterates over what's in list and append

that's my guess :smiley:


#5

you have to use for loop!!

so this is how i did it!

start_list = [5, 3, 1, 2, 4]
square_list = []

for square in start_list: # Your code here!
square=square**2
square_list.append(square)
square_list.sort()
print square_list

study the code and think about it!! before runing try to understand what it those !


#6

Help please! Keeps telling me program took too long! what is wrong? thanks!
start_list = [5, 3, 1, 2, 4]
square_list = []

for number in start_list:
start_list.append(number**2)
start_list.sort()

print square_list


#7

start_list = [5, 3, 1, 2, 4]
square_list = []

for number in start_list:
square = number**2
print square
square_list.append(square)
square_list.sort()

print square_list


#8

well,you may want to check the hint.

here is what I have passed.
start_list = [5, 3, 1, 2, 4]
square_list = []

Your code here!

for number in start_list:
square_list.append(number ** 2) # just use .append and the square for the number in start_list use(number**2) you don't need to print out the square now.
square_list.sort()
print square_list