More with 'For'


#1

I have tired putting in this code to work and when I try to run it , it gives me endless [ ] in the terminal. I do have it indented for the line with start_list.append to the print line.

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

#3

no, looping start list is correct, its not empty. The problem is start_list.append(number**2). each iteration through the loop increases the size of start_list so you never reach the end


#4

good morning to me, you are right. appending to the same list as looping over will causes the loop never to finish


#5

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