Python Lists and Dictionaries 9. Help


#1

Good Morning to you all Ladies and Gents I have come across a problem I need assistance with:

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

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

print square_list

This is the code I have now I know that number is not a valid syntax, but how am I suppose to .append()
every number in start_list to square_list and make every number go through the exponent of two?


#2

Hello @youcantstopit,

The value that you want to append to a list should be inside the parentheses of the method. For instance

my_list.append(value_to_append)

Hope this clears things out for you...


#3

Explain here what the value is and where I put the ** 2 because I was kinda confused as to why you would put code like

for animal in animals:

see animals is a list but how does the computer know what animal is or is it referring to what's in the list
as in you could put anything after for as long as the list name is specified


#4

Hey @youcantstopit,

In pythons for loops, you can use any variable in for loop to define the individual member of the list over which the for loop is iterating over. The value that you are append()ing to the list is number ** 2 which should be put inside the parentheses... Hope this fixes your problems.


#5

Yes it did thank you for helping me have a wonderful day!