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

for word in hellos : print"{} World".format (word) no idea what's wrong with my loop

I wrote the cod shown above I can run it in idle and the output is like the requirements. But i don't know why I cant pass the quiz

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

1 Answer

andren
andren
28,558 Points

In python 3, which is what Treehouse teaches print is a function, and has to be called with parenthesis. You can't leave them off like you have done. That is only valid to do in Python 2, due to print being defined as a statement, not a function in that version of Python.

If you add parenthesis like this:

for word in hellos:
    print("{} World".format(word))

Then your code will work. Though it's also worth mentioning that your use of format is a bit overkill, this task can be solved with simple string concatenation like this:

for word in hellos:
    print(word + " World")

That is the intended solution to this challenge.

woow. You r right. Your code is simple and clean but mine is kind of lengthy.