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

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,089 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,

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

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