Help


#1


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

Help i tried everything i still cant do the exercise if you can give the solution it will be nice


Replace this line with your code. Do not remove the backticks that are above or below this line.
start_list = [5, 3, 1, 2, 4]
square_list = []

# Your code here!


print square_list


#2

Well, if you show us what you tried, we can help you correct the problem

Posting (and asking) for answers is not according to the guide-lines


#3

Okay, so going by the instructions:

1. Write a for-loop that iterates over start_list

To iterate over an array, you'd write a for loop like this:

for item in myArray:
    # Do something with item

2. square each number (x ** 2) in start_list

So you have your placeholder item variable, which in this case is going to be one of the numbers in start_list. You need to square it, which means using the power operator x ** 2 (x to the power of two):

item_squared = item ** 2

3. append the squared number to square_list

To append something to an array, you call .append() like so:

myArray.append(myValue)

4. After the squared numbers have been appended to square_list, sort the list

To sort an array, call .sort():

myArray = [1, 3, 2]

myArray.sort()

# myArray = [1, 2, 3]

As @stetim94 said, we cannot just give you the answers. If you are stuck, don't hesitate to post the code you have tried!

However, I hope you can use what I've written to work out how you should be structuring your answer.


#4


This is what i tried


#5

I think you are pretty close, except for two issues. Lets start with the for loop:

for square_list in start_list:

you want to loop over the items in start_list, so you can append them to your square_list, make sense? So i wouldn't use square_list, it is confusing, lets use item instead:

for item in start_list:

Now, on this line:

square_list.append(start_list ** 2)

what is it we want to append to the square_list? Not the start_list, but one of the items stored in our variable item. If you make this change, it should work, if it is confusing, take a minute to run this loop:

for item in start_list:
    print item

now you will see, this loop prints every item of start_list, which we can append to square_list. Hope this helps


#6

Still doesnt work i tried almost everything just gimme the solution


#7

putting together all the pieces of my previous answer we first update the for loop:

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

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

then, we need to append the item to the list:

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

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