Python Introducing Lists Using Lists Continental

eestsaid
eestsaid
1,311 Points

problem with Continents Challenge

For the continents challenge which is in the introduction to lists course I'm stuck at calling the list items which start with the letter A. The logic I have used below is to use the for loop to call list items only if they start with the letter A (I am assuming the code is incorrect).

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]

for continents_A in continents:
    if [0] == "A":
        print("* " + continents_A)

The error returns

 File "", line 11
    for continents_A in continents:
    ^
IndentationError: unexpected indent

which has really stumped me. Am I on the right path with the original code? Hints (not full solutions would be great). Why is this error showing?

Thanks team.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]

for continents_A in continents:
    if [0] == "A":
        print("* " + continents_A)

1 Answer

Steven Parker
Steven Parker
170,315 Points

That line does not appear to be indented in the code shown above, so I don't understand how it could have an "unexpected indent". But check carefully for tabs or other characters that might not appear here.

But I do see another issue on the next line where there is an index in brackets but the name of the variable being indexed is missing:

    if [0] == "A":              # missing name
    if continents_A[0] == "A":  # fixed
eestsaid
eestsaid
1,311 Points

Thanks Steven - it was the missing name of the variable being indexed.