Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Haider Ali
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Haider Ali
Python Development Techdegree Graduate 24,724 Points

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

This code worked for me.

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