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,086 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.