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 trialJuan Prada
4,429 Pointsi need help with this challege
hellos = [ "Hello", "Tungjatjeta", "Grüßgott", "Вiтаю", "dobrý den", "hyvää päivää", "你好", "早上好" ]
for "hellos": print(hellos {}.format("World")
im really lost here...
2 Answers
Kent Åsvang
18,823 PointsYour for-loop is a bit of, its syntax should look like this :
something = ["stuff1", "stuff2", "stuff3"]
for all_stuff in something:
print(all_stuff)
# Output :
"stuff1"
"stuff2"
"stuff3"
In this challenge you are supposed to print out the word "hello" in different languages from a list, followed by the string "world".
I'll try to explain :
hellos = [ "Hello", "Tungjatjeta", "Grüßgott", "Вiтаю", "dobrý den", "hyvää päivää", "你好", "早上好" ]
# First we must set up a for-loop to reach the items inside the [hellos] - list. Like so :
for item in hellos:
# The word "item" can potentially be whatever you wan't, it's just a placeholder-name for the items inside a iterable.
# the "hellos" basically just tells us which list or iterable we are going to reach inside of.
# Now we must set up the code to print out the wanted string, which is "item + world."
# we can use [format] to put out items inside of a string, with the use of another placeholder "{}".
print("{} world!".format(item))
# which puts the current item where the "{}" is placed. You see ?
# your complete code should be something like this :
for hello in hellos:
print("{} world!".format(hello))
I hope this made it a little bit clearer. English is not my main language so I might explain myself poorly sometimes.
Hope it helped. Good luck.
Chancellor Griffin
2,212 PointsSo this script is looking to print "Hello world" using all the different hellos in different languages.
So I would set up a loop for all the hellos in that list.
something like
hellos = [ "Hello", "Tungjatjeta", "Grüßgott", "Вiтаю", "dobrý den", "hyvää päivää", "你好", "早上好" ]
for hello in hellos:
print("{} World!".format(hello))
So think of the
for hello in hellos:
As saying: Hey python, for each hello in my hellos list, do this.
then you just have the format syntax, which follows the "{} Test".format(whatyouwant) syntax
paris vij
375 PointsThank you , very helpful!
Cheo R
37,150 PointsCheo R
37,150 PointsTo loop through a list you can use:
for index_variable in your_list:
to print the variable in a formatted way use:
print("{} World".format(your_variable))
where {} is replaced by the formatted version of your_variable. Putting it all together you get: