9/14 Help


#1

Can you please let me know what is wrong with my code.

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

Your code here!

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

Thank you


#2

Hi,

My code look like this:

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

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

print square_list

So for each number/element in start_list it multiply it by itself (number ** 2) and then append to the new square list. Then square_list is sorted.

Try reading square_list.append(number ** 2) from the inside to outside. Do stuff in brackets. Then append(stuff).

I hope I helped :smile:


#3

It helps a lot.
Thank you


#4

Thanksyou so much for your help :smile:


#5

First I used:

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

for numbers in start_list:
    i = numbers ** 2
    square_list.append(i)
    square_list.sort()

print square_list

But your example is more elegant....thanks


#6

thx for helping me out :smile: