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

Can anyone help me solve this For Loops Challenge in Python?

Currently learning for loops in python and i am stuck, below is the task:

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".

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

Below is the task with the code I am writing to solve it; hellos = [ "Hello", "Tungjatjeta", "Grüßgott", "Вiтаю", "dobrý den", "hyvää päivää", "你好", "早上好" ] for word in hellos: print(word + "World")

Below is error message I am receiving: Bummer! Didn't find all the "Hello"s.

Can anyone help?

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

1 Answer

AJ Salmon
AJ Salmon
5,675 Points

Hey Roger! When concatenating strings, like with anything else, Python will do exactly what you tell it to do, and nothing more. That means if you want there to be a space in between word and "World", you need to include that space at the start of the string. Right now it would print "HelloWorld" and you need it to print "Hello World". I know you can figure it out :) Happy coding!

Thank you so much, slowly learning how precise coding can be.

AJ Salmon
AJ Salmon
5,675 Points

Hah, you got that right. My pleasure!