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 trial

Python Python Basics (2015) Logic in Python Loop

Why is the loop not finding all strings in list?

I am attempting to figure out why the loop is not finding all the strings in the hellos list. Also, how would I add the "world" to each string in hellos?

for word in hellos: print(word) + "world" ?

I realize that it is in correct.

loop.py
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]

for word in hellos: 
    print(word) 

1 Answer

andren
andren
28,558 Points

Your loop is correct, you are just missing adding the word "World" to them. And your incorrect example is actually far closer to correct than you probably realize.

You do in fact just add the word variable to a string with " World" in it (a space is needed at the start to avoid having the words run together). But you do this inside the print statement, you don't have the + outside it.

So the loop is meant to look like this:

for word in hellos: 
    print(word + " World")