This code does not work. Please help me


#1



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

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


#2

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


#3

The error message is

'NoneType' object has no attribute 'append'.

I want to know how to work this code.


#4

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


#5

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)

#6

Thank you very much.


#7

Thank you very much.
Your advice is useful.


#8

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