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

Matt Law
seal-mask
.a{fill-rule:evenodd;}techdegree
Matt Law
Python Web Development Techdegree Student 904 Points

Marked as incorrect but it is correct and verified through the workspace.

According to the console in work space it printed

All the list items with World added to it.

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

for hello in hellos:
    print(hello, " World")

2 Answers

Moosa Bonomali
Moosa Bonomali
6,297 Points

You are on the right track. However if you use print(hello, " World") The print will add an extra space so that there are 2 spaces between Hello and World. So you could do it this way instead;

print(hello, "World")

With no space in the World

Matt Law
seal-mask
.a{fill-rule:evenodd;}techdegree
Matt Law
Python Web Development Techdegree Student 904 Points

Hey, thanks for the quick response. That fixed it. When should we use spaces, for example, " hello" in strings and when shouldn't we?

Moosa Bonomali
Moosa Bonomali
6,297 Points

I think it depends on how you want to combine the strings, so for example if you were going to combine strings manually you could put a space like so; print("Hello" + " World") But like in your case , the print function adds spaces for you. So the functions you might use to concatenate strings will determine whether it is necessary to manually put spaces in the strings or not.