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 trialAlexander Alcaraz
550 PointsCode looks straight forward but it's not pulling all the hellos?
Something I don't understand from the video is why does the variable word(s) identify as each single word in a list? I tried to combine that with the phrase or string "World" but it's not pulling all the different languages. What am I doing wrong or what can I reference to fix this piece of code?
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
for words in hellos:
print(words + "World")
2 Answers
reanimator313
6,005 Pointsyour code output is :
#example
'HelloWorld'
output must be:
'Hello World'
#a space
print(words+" World")
Thananjaya Chakravarthy
4,672 PointsAnswer to your first question... "How/why the variable 'words' is identified as a single word in list?"
That's because, we are using 'in' operator. The 'in' operator is a membership operator which assigns each element in the list (in this case, its 'hellos') to the variable "words".
Answer to your second question..."Your code looks fine".. It is running properly in my workspace..
Alexander Alcaraz
550 PointsThank you for your explanation of the 'in' operator! The problem with the code was just the spacing and how the code challenge page gives error codes or format.