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 trialAndreas Wassberg
5,856 Pointscan only concatenate list (not "str") to list Code Challange - Loop
Hi,
I have been working on this problem for several hours and I cant seem to solve this challenge. Can someboy help me?
Challenge Task 1 of 1 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ää", "你好", "早上好" ]
a = " World"
for word in hellos: hellos + ', '.join(a) print(hellos) break
7 Answers
Ferdinand Pretorius
18,705 PointsHi Andreas,
You are very close to the answer, here is how I would do it:
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
for word in hellos:
print(word + " World")
Hope this helps!
Mars Epaecap
5,110 Pointsthere's a space in her code
" World" in print(word + " World") as oppose to what I had "World"
matthew tomasetti
1,887 PointsThe space in " World" killed me.
Andreas Wassberg
5,856 PointsHi guys,
Thanks for the answer. It worked out fine!
//Andreas
Ferdinand Pretorius
18,705 PointsYou're welcome, happy coding!
Patric Daniel Pförtner
1,542 PointsHi Andreas,
You are very close to the answer, here is how I did it:
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
for word in hellos:
print(word + " World")
Why are you learning Python? Maybe we have the same aims! I am learning it to bring my Start UP www.wolf-gate.com to the next level. Thank´s to Kenneth Love it´s easily possible :)
Sandeep Krishnan
9,730 Pointsfor word in hellos: print(word {}.format(" World"))
I tried this but it didn't work for me
Kenneth Love
Treehouse Guest TeacherYou need to concatenate the word
variable to the "{}"
string.
Sandeep Krishnan
9,730 Pointsthanks Kenneth.
shamlan Al-Olayan
498 PointsThe problem that got me is in the question not in the code :p
Jason Prince
5,113 Points# List of different ways to say "Hello".
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
# Each time the loop cycles it will assign one of the list items to the variable hello.
# It will do this in order of left to right until the end of the list.
# Example: 1st loop, hello = "Hello". 2nd loop, hello = "Tungjatjeta". 3rd loop, hello = "Grüßgott".
for hello in hellos:
greeting = hello + " World" # Concatenate the list item variable to the string " World".
print(greeting) # Displays the concatenated string
David Cox
671 PointsI was having trouble with this until I looked for help. I had it correct but why do we need to put a space between the double quote and World?
Kenneth Love
Treehouse Guest TeacherKenneth Love
Treehouse Guest Teacher.join()
is for joining the items in an iterable (something that has multiple items). Joining youra
variable would produce" ,W,o,r,l,d"
which isn't at al what you want. Also,hellos +
the join won't do what you're thinking, either.