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

Nicholas Anstis
Nicholas Anstis
2,095 Points

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

I don't know what do to do. :P

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

for hellos in world:
  print(hellos + world)

  world = world

3 Answers

Hi Nicholas, you have the basic idea right, only there are a couple of places where you are going wrong. Firstly, you should be looping through the list hellos. For each greeting in hellos you should print that greeting plus " World". You have forgotten your quote marks around 'world' which makes the challenge think you are attempting to print a variable called world whereas this is not the case. Lastly, the challenge doesn't ask you to define a variable called world so if you leave that out your code should look like this;

for greeting in hellos:
  print(greeting + " World")

If you have any further questions please leave a comment :)

Thanks,

Haider

Nicholas Anstis
Nicholas Anstis
2,095 Points

Thank you! That was of great help :D

Does anyone see an issue with my code?

I am getting an error when trying to validate the code

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

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

At the beginning of the "World" string you need a space otherwise the words will be right next to each other like this:

HelloWorld

This code worked for me.

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