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

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")