Python Introducing Lists Using Lists Continental

Michael Kaminski
Michael Kaminski
1,320 Points

I am having trouble printing the proper items in the list, but I think that the code I wrote should work.

I am using a loop, as that is what I am led to believe the question calls for, but I receive a notification that my code is wrong even though it produces the proper result. Can someone provide a really strong hint for this, because I have been trying to solve this and can not.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for continent in continents:
    print("* ", continents[0])
    print("* ", continents[1])
    break

1 Answer

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 24,273 Points

You are pretty close to the proper syntax and block structure-- let's build on that. Since you are really close, I am not going to spoil the victory for you, but hint at the solution.

The loop works such that it iterates over a list. Here's an example where a list is named 'cities'. Each time the block nested under the for loop runs, it will print a new city name.

You don't need a "break" statement in the block. When the loop completes, it will exit.

print("Here are some cities I have visited:")
cities = ['Portland', 'Detroit','New York','Chicago','Los Angeles']
for city in cities:
    print(city)
print("Done!")

It will have this output

Here are some cities I have visited:
Portland
Detroit
New York
Chicago
Los Angeles
Done!

Good luck with your Python journey!