This code does not work. Please help me


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

# Your code here!
for x in start_list:
    square_list = square_list.append(x ** 2)
print square_list


In what way isn't it working?
What information are you missing to fix it?


The error message is

'NoneType' object has no attribute 'append'.

I want to know how to work this code.


NoneType is a type like int or list, and it has a single value: None
None represents lack of value, it is for example what functions return if they have no explicit return value

Since the error says that None has no append attribute, then you can take a quick look at your code and see that there's one place where you use append, so it's likely that what you used append on has the value None - this is something you can confirm by adding a print before appending. Once confirmed that this is indeed the case, you would then consider where you last assigned to that value, where you got the None from


X should not be a the name there, it should be "number"

so it should be:

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


Thank you very much.


Thank you very much.
Your advice is useful.


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