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 trialvictor E
19,146 Pointsno clue what I'm doing here...
I kinda hit a wall with loops. I think that if I see an example I will do better.
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]for hellos:
print names+ "World"
3 Answers
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Victor
Imagine you had a basket of fruits. imagine the list as a basket. see example below
basket = [
'apple',
'mango',
'grapes',
]
# if i wanted to print out each fruit from my basket, thats where a for loop comes in to play,
#for something in something, in this case for fruits in basket
count = 0
for fruits in basket:
count +=1
print( "fruit {} is a {}".format(count, fruits))
# result should be
# fruit 1 is apple
# fruit 2 is mango
# fruit 3 is grapes
hope this makes sense, try and see if you can solve the challenge now
victor E
19,146 Pointsthank you, I tried it and the example you gave me worked thank you! I don't know if it is the exact syntax that is necessary but I am still getting it wrong :(
Andreas cormack
Python Web Development Techdegree Graduate 33,011 Pointswhen you say getting it wrong, do you mean you cannot pass the challenge ?
victor E
19,146 Pointsyeah, I cannot pass the challenge. I do not know how to add the word "world" at the end of each word for the loop. I felt comfortable enough to create a loop that calculates interest on an investment, but I cannot seem to figure out how to add this word at the end of each word when I print the list lol.
Andreas cormack
Python Web Development Techdegree Graduate 33,011 PointsHi Victor
you could either concatenate the string with the word "world" or use a placeholder and the format method. see example below
# example 1
print( "Hello "+"World")
# result will be : Hello World
# example 2
print("Hello {}".format("World"))
# result will be : Hello World
hope this helps