Python Introducing Lists Using Lists Continental

Hey can someone please explain to me why this does not work and how it would work?

I tried this code

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

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 49,924 Points

Not sure what you have there:

  • You are using assignment operators in an if statement that don't make sense
  • i in your for in loop is a string but you try to use it as an index in continents[i][0]
  • You need to indent your print statement to be the code executed by your if statement

This would work

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

In the code above i is each continent name and i[0] is the first character in the name. The comparison operator == is used to compare the character to "A" and if true print the bulleted name.