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

clarification on loops

How do I add a word to a list using loops?

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

5 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Your line of code

print("Hello " + "World")

Won't that always say "Hello World"? I think you want to use the variable hello you are introducing in your for loop, right?

Let me know if that hint doesn't do the trick ;)

Thank you. It worked.

Bummer! Didn't find 'Tungjatjeta World' in your output. Restart

Not clear on what im doing wrong.

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

Wrap your code with 3 backticks (```) on the line before and after.

A few things:

  • Need to start the loop completely under the list
  • Each time through the loop you need to concatenate the string "World" to the current item the loop is on
  • Don't forget the space between the two words

Let me know if this helps here

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

Please paste the code w/ markdown formatting