Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
HARMANDEEP PANNU2,077 Points
I need you to write a for loop that goes through each of the words in hellos and prints each word plus the word "World".
I need you to write a for loop that goes through each of the words in hellos and prints each word plus the word "World". So, for example, the first iteration would print "Hello World".
hellos = [ "Hello", "Tungjatjeta", "Grüßgott", "Вiтаю", "dobrý den", "hyvää päivää", "你好", "早上好" ] for words in hellos: print(hellos + " " + "World")
Jose Soto23,407 Points
It might help to see the issue by reading the for loop. In this example, the loop will read:
wordsin the array
hellosplus the string "World".
When you read it like this, you can see that you shouldn't be printing
hellos, but the
word within the array.
Your loop should look like this:
for word in hellos print(word + " " + "World")
Antonio De Rose20,882 Points
for words in hellos:#what does words have stored, and what does hellos have got print(hellos + " " + "World")#what are you trying to print here #all seem good, except for 'hellos' in the print statement #you are trying to concatenate, an array with a string
I was facing the same problem. I suggest removing the + " " + -- it's not needed. Add a space to " World" and it should be fine. Mine was.
Amekha Sritaboot795 Points
for word in hellos:
print(word + " World")
This should be fine. Try it.
for greeting in hellos: print(greeting + " World")