Python Introducing Lists Using Lists Continental

SARA PARACHA
SARA PARACHA
233 Points

Quiz:Task2

Challenge Task 2 of 2 I'd like you to now only print continents that begin with the letter "A".

HINT: Remember that you can access characters in a string by index

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for c in continents:
    c== A
    print(c)
SARA PARACHA
SARA PARACHA
233 Points

Please someone Help me in answering this question.I'm stuck

youssef b10ta
youssef b10ta
Pro Student 2,754 Points

your code is good u need just to do use if statments and check if the first index on the c is == 'A' like this

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for c in continents:
    if c[0] == 'A':
        print(c)

1 Answer

Steven Parker
Steven Parker
182,603 Points

Here's a couple of hints:

  • to control other statements, use an "if" statement
  • a literal string needs to be enclosed in quotes (like "A")
  • variable "c" will contain the entire name, but you want to test only the first character
  • individual characters can be selected from a string with indexing (a number in brackets)