# More of 'for'

#1

I have no idea what todo could I have some assistance please??

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

for square_list in square_list:
print square_list``````

#2

umbers = [5, 3, 1, 2, 4]
numbers_squre = []

for number in numbers:

numbers_squre.append(number**2)
numbers_squre.sort()

print numbers_squre

#3

here is the correct code

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

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

square_list.sort()

print square_list``````

don't forget to examine the differences

#5

start_list.append()
for start_list in start_list:
square_list = start_list**2
square_list.sort()
print square_list
this was my code. i think i understand why you have x. is it because it for the numbers in start_list? Also can you explain you code. I kind of get some of it but not really. Like i thought that you had to do square_list.append() and then = it to x**2. Why have it in the () if nothing in the square_list.sort(). i understand that it just sort the list but then why. Thanks in advance.

#6

Thanks for the excellent answer! This code confuses me because I thought that "x" had to be defined as representing the items in the start_list before it could be used. Does the "for x in the start_list" define "x"?

I did it this way as well as the way you did it and it worked:

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

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

#7

#8

Thanks these messages really helped thanks

#9

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