More with 'for'


Here is what I have. I know im missing something but cant seem to figure it out. Any advice would be much appreciated.

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

# Your code here!
for square_list in start_list:
  square_list ** 2
print square_list

#result given = 4


can you share the exercise url? Not sure what the instructions are

this is risky:

for square_list in start_list:

now the loop iterator (square_list) will overwrite the list you defined with this name earlier. So why would you use square_list here?

then inside the loop, you do square list to the power 2, but nothing with the result of this math

then you print square_list after the loop, which will contain last value of list


Thank you for the reply. I ended up playing around with it and realized I needed to create an entirely new variable. I ended up passing the lesson with this:

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

Your code here!

for new_list in start_list:
square_list.append(new_list ** 2)

print square_list

Which gave this answer: [1, 4, 9, 16, 25]


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.