Python Introducing Lists Using Lists Continental

Farhan Murad
Farhan Murad
1,920 Points

Intro to List

I have to print continents beginning with the letter "A". Can someone help me do that?

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

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 58,993 Points

Hint: Given that in each loop, continent contains the string name:

  • The first character of some string can be reference using string[0], or
  • The method string.startswith() returns a Boolean if the argument matches the beginning of the string

Add an if statement that uses one of the above comparisons and prints only conditions are correct.

Post back if you need more help. Good luck!!