Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics (2015) Logic in Python Loop

Joshua Hoy
Joshua Hoy
533 Points

Can't find all Hello's?

I thought it would be as simple the code I wrote, seems to not pick up all Hello's

I also deleted certain parts of the code as i thought my browser/computer doesn't support or know what mandarin or cantonese were (Sorry if those weren't the languages!)

loop.py
hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää"
]
for hellos in [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää"
]:
    print (hellos + "World")
Nick Lenzi
Nick Lenzi
7,979 Points

You're actually really close. when you are using a for loop to iterate through a list whatever follows for is a temporary variable

random_list = ['bananas', 'pears', 'oranges']

for  fruit in random_list:      #fruit has no meaning until I used it as the reference for what's being iterated
    print(fruit)
                                               #the temporary variable only has meaning within the scope of the loop 
                                               #and can be literally any variable
for x in random_list:
for doohicky in random_list:
for mick_jagger in random_list:

So any variable can be used as long as it isn't a preset variable already defined.

for (temp variable) in (list to be iterated from):

Hope that helps :)

Noah Fields
Noah Fields
13,985 Points

The problem here seems to be that you are writing the list twice. Instead of beginning with hellos, and then writing it again for your loop, try this:

hellos = [
    "Hello",
    "Tungjatjeta",
    "Grüßgott",
    "Вiтаю",
    "dobrý den",
    "hyvää päivää"
]

for x in hellos:
    print (x + "World")