More with 'for'


#1

I have this error "Oops, try again. Make sure not to modify start_list!".

My code:

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

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

print square_list

And the result is True in the Console:

[1, 4, 9, 16, 25]
None

Where I have modify "start_list"?

Thanks for your help


#2

you modify start_list here:

start_list = number ** 2

you could name this variable things, start_list isn't one of them

yes, the loop will succesfully continue looping, but see what happens when you print start_list after the loop, its modified


#3

I get 16 when I print after the loop :confused:

I do that and it works:

x = number ** 2
square_list.append(x)

My way to code is clean?


#4

which means you modified the list.

i would append number ** 2 directly to the square_lit, but for the rest its clean


#5

Thanks for your advice and your help :slight_smile:


#6