Square_list


#1

https://www.codecademy.com/courses/learn-python/lessons/python-lists-and-dictionaries/exercises/more-with-for?action=lesson_resume

I am confused I came up with the same code and it will not work doesn’t give me any errors just takes awhile for it to just say it is wrong.

when i enter it in repl.it it gives me this

Traceback (most recent call last):
File “python”, line 9
print square_list
^
SyntaxError: Missing parentheses in call to ‘print’


9. More with 'For'
#2

May we see your code, please?


#3

I had to add the arrow to show that I indented it because it doesnt show on here

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

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

square_list.sort[]

print square_list


#4

That will create an infinite loop. You are appending the wrong list, and it should not be an assignment.

square_list.append(number ** 2)

See the difference?

As you may have discovered, the return value of append() is None. There is nothing to assign. Methods are like that a lot of the time. They act upon their object directly, in a single statement.


#5

You are correct, thank you, I fixed my coding and it was successful!


#6

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