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")'''

adam n
adam n
53,796 Points

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

adam n
adam n
53,796 Points

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")
adam n
adam n
53,796 Points

Please paste the code w/ markdown formatting