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 Introducing Lists Using Lists Continental

HARUN SAPLI
HARUN SAPLI
2,581 Points

i dont know how to stop looping

i couldnt make to stop to code

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

1 Answer

Moosa Bonomali
Moosa Bonomali
6,297 Points

Your for loop is extracting the data in the continents array , so there is no need to use indexing. The code could be like this;

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

The loop will automatically exit when it has gone through all the continents.

Now if you really wanted to use indexing, you could do it like this;

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for i in range(len(continents)):        
    print("* "+continents[i])

There are other ways of using indexing, but if there is no special reason for such, I suggest to do it the way you have and just make the minor corrections.