Stupid code throws errors


#1

My code is throwing a super-weird error; I can't think what could go wrong! Code:

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

start_list.sort()
for square_list in start_list:
    sqaure_list.append(start_list ** 2)

print square_list

And returns

Traceback (most recent call last):
  File "python", line 6, in <module>
NameError: name 'sqaure_list' is not defined

#2

the error is thrown because here:

sqaure_list.append

you misspelled square

anyway, why do you use square_list as loop iterator? This will overwrite your empty square_list

finally, you need to append the square of each item in start_list to square_list, not the square of start_list itself, not sure how that will look


#3

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