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

David Lopes
David Lopes
827 Points

Not sure what i'm doing wrong

Not sure what I did wrong, it says that all the hellos does not show, but when I check preview it does show all of them

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

1 Answer

Jason Anders
MOD
Jason Anders
Treehouse Moderator 145,624 Points

Hey David,

You are really close. You just need to specify a different variable for use in the loop iteration. Right now you are using the same name as the dictionary. The general rule is to use the singular version for the temporary variable being used for the loop. So, in this case, you would use hello.

Also, you will need to add a space in the "world" string so it looks like " world". This is so there will be a space between the the "Hello World"s.

Have a look at the completed code below and see if it makes sense.

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

Keep Coding! :) :dizzy:

David Lopes
David Lopes
827 Points

Really helpful. Thanks!