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

Ryan Sladek
Ryan Sladek
427 Points

How do I add "World"?

I can't figure out how to add the word "World" to the loop for each hello in a language.

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

1 Answer

Steven Parker
Steven Parker
231,275 Points

There's two ways I can think of offhand:

  • you could use the format function
  • you could use simple string concatenation (+)
Ryan Sladek
Ryan Sladek
427 Points

Thanks Steven. I've tried:

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

but it says there is a syntax error.

Edit I figured it out. Thanks for the help!

Steven Parker
Steven Parker
231,275 Points

That's exactly what I was hinting in the second suggestion. I even pasted your code into the challenge and it passed.

Were you careful to add that code after the provided array, and not make any changes to the array itself?