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

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,858 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!