Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialCalvin Turner
274 PointsI'm so stuck on this question, feeling a bit useless. I don't recognise num?
Trying to figure out this question but typing help(num) obviously came out invalid and then i got stuck with a "logout"
Feeling like i'm never going to get this.
Complete the for loop below:
>>> my_list = [1, 2, 3, 4]
>>> num my_list:
... print(num)
1
2
3
4
1 Answer
rayorke
27,709 PointsHi Calvin!
So, it's helpful here to remember that you're creating a for loop, which follows the basic syntax:
y = [ 1, 2, 3, 4 ] # Your list
for x in y:
print x
This basically says for every item(x) in the list(y), process the code within the loop until you reach the end of the list - in the example, you're printing to the screen using print x.
So in the case of the question in the quiz, num is simply what you are assigning to represent each item in the list.
it could easily be...
barrel = [ "granny smith", "delicious", "mcintosh"] # Your list
for apples in barrel:
print apples
I hope that helps to clarify things a bit!
Kuhn Seo
829 PointsKuhn Seo
829 PointsThis really cleared things up for me, thank you!