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 trialHARMANDEEP PANNU
2,077 PointsI 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 need you to write a for loop that goes through each of the words in hellos and prints each word plus the word "World". So, for example, the first iteration would print "Hello World".
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
for words in hellos:
print(hellos + " " + "World")
7 Answers
Jose Soto
23,407 PointsIt might help to see the issue by reading the for loop. In this example, the loop will read:
For every
words
in the arrayhellos
, printhellos
plus the string "World".
When you read it like this, you can see that you shouldn't be printing hellos
, but the word
within the array.
Your loop should look like this:
for word in hellos
print(word + " " + "World")
Sree Vishnu Thiyagarajan
1,226 Pointsfor words in hellos: print("{} world".format(words))
Antonio De Rose
20,885 Pointsfor words in hellos:#what does words have stored, and what does hellos have got
print(hellos + " " + "World")#what are you trying to print here
#all seem good, except for 'hellos' in the print statement
#you are trying to concatenate, an array with a string
Burton King
3,938 PointsI was facing the same problem. I suggest removing the + " " + -- it's not needed. Add a space to " World" and it should be fine. Mine was.
Amekha Sritaboot
795 PointsHey guys,
for word in hellos:
print(word + " World")
This should be fine. Try it.
James Reinhold
12,361 Pointsfor greeting in hellos:
print(greeting + " World")
Mike Van Amburg
8,544 Pointsfor hellos in hellos : print (hellos + " World")
khamarul mokhtar
552 Pointskhamarul mokhtar
552 Pointshi jose, my code on this challenge doesn't work, i used the variable word but there's still a bummer saying they didn't find all the "hello"s, mind for helping ?, thanks
Jose Soto
23,407 PointsJose Soto
23,407 Pointskhamarul mokhtar Post your code here and someone will help you.