Python Introducing Lists Using Lists Continental

Hey guys, I'm looking for help with indexing in python. I'm supposed to print out continents that start with A only.

There are 7 continents and only those beginning with A are wanted.

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

print("Continents:")
for continent in continents:
    print("* " + continent)
a = continents[0]
b = continents[3]
c = continents[5]
d = continents[6]
A = a + b + c + d
print("Suggested continents:", A)

1 Answer

Steven Parker
Steven Parker
172,269 Points

You don't want to tie your code to specific indexes, what if the list gets changed later?

But your original loop will do the job, with just a conditional statement added to control the "print". So put an "if" statement before the "print" with an expression that compares the first character of the current continent with the letter "A".

Thank you let me try and do that.

Steven Parker
Steven Parker
172,269 Points

Panashe Mutsikwi — Write again if you need more help, and otherwise you can mark the question solved by choosing a "best answer".
Happy coding!