9.Python Lists and Dics


#1
> 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

Here's my code, by theory it's right but I mights be missing something, there are no errors but codecademy is saying to check for infinite loop?


#2

You made an infinite loop, as start_list will grow forever. Example:

start_list = [1,2,3] #Easy Values To Understand
#If run through your loop
#Num is 1, append 1 * 1 = 1, infinite 1's

You should instead change start_list inside of the loop to square_list. Here:

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

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

#3

Oh I guess I got confused :joy: But thanks a lot for the great help