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 trialJohn Frauenhoffer
2,008 PointsProblem with multiple hellos and adding 'World' loop
Hello guys,
I was wondering if you could look at my code and help me understand what I'm doing syntax wise in my 'for' loop that is messing this up. Thanks
hellos = [
"Hello",
"Tungjatjeta",
"Grüßgott",
"Вiтаю",
"dobrý den",
"hyvää päivää",
"你好",
"早上好"
]
for hello in hellos:
print(hellos) + 'World'
continue
1 Answer
Per Karlsson
12,683 PointsHey John
You need to convert the hello to a string, try something like this instead.
for hello in hellos:
print(str(hello) + " World")
Regards, Per
John Frauenhoffer
2,008 PointsIt worked! Thx
Jeremy Hill
29,567 PointsJeremy Hill
29,567 PointsIn your line: hello in hellos the keyword 'hello' is acting as a single placeholder for the loop; the keyword 'hellos' is the entity being looped. Everything in the parenthesis is being printed and I noticed that you have "+ 'World' outside of your parenthesis. So in short, you need to print each individual item in the list 'hellos' by using the keyword 'hello' in your print statement and make sure that your "+ 'World'" is inside of your parenthesis in your print statement.
Does that make sense?