More with 'for'


#1

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

After "Save&Submit Code",it shows this ERROR!
The program took too long to finish. Check your code for infinite loops and try again.
What's the problem?


#2

your appending to the same list as you are looping over, causing an infinity loop

sure you are appending to the right list?


#3

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

ok!


#4

I tried the same thing:

And it told me:
File "python", line 6
square_list.append(number**2)
^
IndentationError: expected an indented block

Wait never mind I see it


#5

well, on the forum indention doesn't show unless you use markup (which hasn't been used)

if you have problems, please make a new topic


#6