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.

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