1.9 More with 'for'


#1

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

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

print square_list

Traceback (most recent call last):
File “python”, line 6, in
AttributeError: ‘int’ object has no attribute ‘append’

What is wrong in my code? How can I fix this error message?


#2

this will solve your issue its more like you need to do indentation for the loop

start_list = [5, 3, 1, 2, 4]
square_list = []
for i in start_list:
square_list.append(i**2)
square_list.sort()
print square_list

happy coding!


#3

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