Having Trouble with For Loops



The code I am working on is returning the following error:
File "python", line 5
for number in square_list
SyntaxError: invalid syntax

It should be returning the squared values of start_list in the variable square_list.

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

for number in square_list
return number**2

print square_list

I believe the issue is with my for loop but I'm not sure what's incorrect about it.


HI first this line

for number in square_list

you should add the : at the end of it.. then you should indent this line inside the for loop

return number**2

then change the return with print


hi,you can't use square_list.append(start_list) directly.and in your for loop ,the object is start_list but not square_list.
you can code like this:
for number in start_list:
square_list.append(number ** 2)

good luck!


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