"More with 'for' exercise and i am stuck


#1

https://www.codecademy.com/en/courses/python-beginner-en-pwmb1/1/6?curriculum_id=4f89dab3d788890003000096

Error message: Oops, try again. square_list should be the same length as start_list

Not sure what is wrong here.

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


#2

Check your code for typo in the first line.


#3

This is how the code looks
start_list = [5, 3, 1, 2, 4]
square_list = []
for x in start_list:
print x**2
square_list.append(x**2)
square_list.sort()
print square_list

I still get the same error message:
Oops, try again. square_list should be the same length as start_list


#4

I tried troubleshooting what you had and after commenting out a few sections, the square_list just included the value "4" for some reason. No idea why x=4. I think where you're running into trouble is the print function. The print function will cause the for loop to just output the squared start_list instead of placing the squared values in the square_list.

Try replacing the print function in the

for x in start_list:
print x**2

portion with the append feature. Think of it as the for loop outputting directly into the square_list, if that helps. After this (should be just 2 lines of code), you can sort and print. Hope this helps!


#6

take out print x**2
and place that in the parenthesis in .append

should look like this

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

print square_list


#7