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

Question down below

I need you to write a for loop that goes through each of the words in hellos and prints each word plus the word "World". So, for example, the first iteration would print "Hello World".

Error is Bummer! Didn't find all the hello's.

Any help appreciated

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

for hello in hellos:
    print (str(hellos) + " World")

1 Answer

Gyorgy Andorka
Gyorgy Andorka
13,811 Points

I'm not sure if it's just a typo on your part, or maybe a misunderstanding regarding the workings of the for loop, but the item we'd like to concatenate with " World" is hello, not hellos (the whole list). The code for hello in hellos: ... basically means: for each item (to which we refer in each iteration by the name hello, but that's arbitrary, it could be item or anything else) in hellos, do the following: [the contents of the next line].

Moreover, converting the item to string is redundant in this case, since the list only contains string objects here. So inside the loop just write print(hello + " World").

That still doesn't work it gets another error and it doesn't even work in IDLE neither, the str( is needed 100%

Gyorgy Andorka
Gyorgy Andorka
13,811 Points

There is also an unnecessary space between print and the braces (there shouldn't be). Now the could should work.