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

Stefan Vaziri
Stefan Vaziri
17,453 Points

Help!

I'm not sure how to add "World" to each word in the hellos list.

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

4 Answers

Anish Walawalkar
Anish Walawalkar
8,534 Points

Hey, you were on the right track there with the for loop.

for hello in hellos:
  print("{} World".format(hello))

In the for loop I'm printing the string "{} World" and the format(hello) function just replaces {} with the string value of hello

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Stefan,

the beginning of your loop is correct. But you don't need an if here so you can remove that. To add the World to the "hello"s you can just concatenate the variable and the String " World" and print it out like this:

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

for hello in hellos:
  print(hello + " World")
Anish Walawalkar
Anish Walawalkar
8,534 Points

In your print statement it should be hello not word

Tobias Helmrich
Tobias Helmrich
31,603 Points

Hey Anish,

I fixed this immediately after I sent it, I just had it different in my version and noticed that Stefan used hello instead of my word but forgot to change the second one. But thanks for the heads up! :)

Stefan Vaziri
Stefan Vaziri
17,453 Points

Thanks you two! I tried both and both worked great!!

Tobias Helmrich
Tobias Helmrich
31,603 Points

No problem, I'm glad you got it working! Happy coding! :)

Stefan Vaziri
Stefan Vaziri
17,453 Points

Thanks you two! I tried both and both worked great!!