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

Sean Kochel
Sean Kochel
1,693 Points

For and While loop in Python

I'm unsure of why my attached code isn't working. It seems rather straightforward: for each word in the list "hellos", print the word + "World". Do I need to set another variable/list to store the values in or something?

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

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

2 Answers

You are doing a great job! I like how you just concatenate the strings together instead of using the "format" function. However, the Treehouse code challenges are picky. If you do something like this:

"Hello" + "World"

Then Python will return "HelloWorld", while the code challenge will expect "Hello World". All you need is to add a space before the "World"!

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

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

Hope that helps! :dizzy:

Sean Kochel
Sean Kochel
1,693 Points

Thank you kindly sir or madam

anil rahman
anil rahman
7,786 Points
for word in hellos:
   print (word + " World") //you were missing the space before the W