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

Lucas Frischmann
Lucas Frischmann
1,397 Points

Invalid Syntax in for loop

Hey team,

Why do I get a syntax error here? If I run it on Jupyter notebook it's printing out fine!

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

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

2 Answers

Nathaniel Bell
Nathaniel Bell
6,020 Points

I think you only need to wrap the print with parens and you will be all set!

print("{} World".format(word))
Lucas Frischmann
Lucas Frischmann
1,397 Points

Thanks, Nathaniel, good point. But still get a syntax error :(

Nathaniel Bell
Nathaniel Bell
6,020 Points

Can you paste your entire code again? I cut and pasted your original, added the parens, and it worked beautifully...

Lucas Frischmann
Lucas Frischmann
1,397 Points

Thanks Nathaniel for your help. Just copy paste the code again and it works now :( *weird