Python Introducing Lists Using Lists Continental

Alberto Serafini
seal-mask
.a{fill-rule:evenodd;}techdegree
Alberto Serafini
Python Development Techdegree Student 1,211 Points

index

I can't solve the second part of the challenge when it is asking to print the continents with the initial "A" . Can anybody please help? Thank you!

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

5 Answers

Steven Parker
Steven Parker
202,109 Points

You need to add an "if" statement to control when the "print" is done. Give it a conditional expression comparing the first character of "continent" to the letter "A".

You can isolate a character in a string using an index (value in brackets).

Steven Parker
Steven Parker
202,109 Points

It's impossible to check the indentation without Markdown formatting (as I used below), but if your indentation is already correct it looks like you're only missing the colon at the end of the "if" line:

for continent in continents:
    if continent[0] == "A":      # <-- colon added
        print("* " + continent)
Steven Parker
Steven Parker
202,109 Points

Try adding an "if" statement using the hints given. If you still have trouble, show the new version.

Stephen Williams
Stephen Williams
3,234 Points

I'm confused on why this works.. in the if statement you put ( if continent[0] == "A": ) so wouldn't the computer only check and print the location of continent[0] which is Asia instead of printing out the other continents? I hope this made sense.

Alberto Serafini
seal-mask
.a{fill-rule:evenodd;}techdegree
Alberto Serafini
Python Development Techdegree Student 1,211 Points

So Steven I've been trying lots of things maybe the less embarrassing version i wrote is: for continent in continents : if continent[0] == "A" print("* " + continent) And obviously is wrong.