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
hellos = [
    "dobrý den",
    "hyvää päivää",
worlds=word + world
for words in hellos:

2 Answers

Steve Hunter
Steve Hunter
Treehouse Moderator 57,652 Points

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,


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')
Steve Hunter
Steve Hunter
Treehouse Moderator 57,652 Points

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