More with 'For'


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)
  print square_list.


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


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


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