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

faraz malik
faraz malik
2,118 Points

Can anyone correct this solution?

challenge task of for loop

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

2 Answers

Hi there,

You want to loop through hellos using a for loop. Inside the loop add the word "World " ahead of each element in the list.

The for loop could look like:

for hello in hellos:

So, each element will be contained in the variable hello with each loop. To do the printing, use the ```format method to insert the element before the word "World" - we can include a space easily, that way:

print("{} World".format(hello))

I hope that makes sense,

Steve.

Andrew Bruce
Andrew Bruce
7,822 Points

You need to add world as a string, so it needs to be in quotes. This code works for me -

for words in hellos:
    print(words + ' world')

I switched your comment to be an answer - you posted as I was typing! :+1: