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 trial

Python Python Basics (2015) Logic in Python Loop

Kade Carlson
Kade Carlson
5,928 Points

These loops are giving me some trouble

I can't figure out how to execute this loop

loop.py
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]
for word in hellos:
    if word == hellos
    print(word + world)

2 Answers

Julian Gutierrez
Julian Gutierrez
19,201 Points

Kade Carlson you're close, there is no need for the if statement and make sure world is a string by adding quotes around it. Also be sure to include the space in your string.

for word in hellos:
    print(word + " world")

I don't think you are understanding the difference between a variable and a string. You should go back and master that before you continue. Also an if conditional statement is not required. You aren't testing the value for some parameter, you are simply getting a word from the list and printing it with the word world added to the statement.

hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää",
    "你好",
    "早上好"
]
for word in hellos:
     print(word + ' world!')