More with 'for'


#1




The error message comes "Error:The program took too long to finish. Check your code for infinite loops and try again."


I expect the loop to work and store the numbers of start_list in square_list, squared, and print square_list


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

# Your code here!
for number in start_list:
    start_list.append( number ** 2)
    start_list.sort
    


print square_list


#2

You need parenthesis to use the sort method, so it would look like:

start_list.sort()

Everything else is good, hope this helps. :slight_smile:


#3

Your code has what is essentially an infinite loop.

The program should append each number ** 2 to square_list.

For best efficiency, sort the square_list after the loop, rather than within it.


#4

All this helped. Thanks.


#5

I just want to say that in my code I put the for loop as: for x in start list:


#6

just saying it also works


#7