9/14 help


Hey everyone I’m stuck on what is wrong. Was hoping for someone to point me in the right direction. Here’s my code:

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

for square_list in start_list
square_list.append(number ** 2)

print square_list

for square_list in start_list
square_list.append(number ** 2)

You’re trying to find a number within start_list, not a square_list.


I apologize if this is being dense, but how does “python” know what list number refers too?

For example, I assume that square_list also has a number value, in this case ‘0’.


I wrote number, but it could have been item, word, fruit…

Say I want to go through my fruit basket:

for fruit in fruit_basket
// do something awesome

We’re going through the fruit basket, picking every fruit one by one.
Python knows what you’re referring to because you’re telling the program that you’re looking…

… for fruit within fruit_basket

As for what list it refers to, well because you’re saying it:
in fruit_basket

This precise example says “Okay, go through the fruit basket, list every fruit that’s in there, and place them somewhere else” (.append to another place, could be another fruit basket).


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