More with "for"


#1

Here is my Code
start_list = [5, 3, 1, 2, 4]
square_list = []

Your code here!

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

square_list.sort
print square_list

it keeps saying: "Oops, try again. Make sure to sort square_list after filling it!"

And I am confused because I looked at other posts and this seems like it would work.


#2

you did good - try spacing ... for (for) you need spacing
for number in start_list:
[SPACe}square_list.append(number**2)
[Space}square_list.sort
print square_list


#3

Oh thanks. I keep making stupid mistakes. And all the time I was scratching my head at other people's code because it was almost identical to mine


#4

:grinning::grin::sunglasses:


#5

This statement is syntactically correct, but it does not actually perform any useful action, such as sorting square_list.

square_list.sort

Because it does not have parentheses, the statement essentially references the name of the sort method, without causing it to execute. To sort the list, call the method, as follows ...

square_list.sort()

#6

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