Stupid code throws errors


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 = []

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


the error is thrown because here:


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


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