Having Trouble with For Loops


#1



https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/1/6?curriculum_id=4f89dab3d788890003000096#

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 = []

square_list.append(start_list)
for number in square_list
return number**2

square_list.sort()
print square_list

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


#2

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


#3

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!


#4

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