Python Introducing Lists Using Lists Continental

Daron Anderson
Daron Anderson
1,967 Points

Need insight on how to Print out all the continents that start with an 'A'. the square brackets & parens. confuse me.

"There has to be one and only one obvious way to solve it" Thanks in Advance!!!

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

4 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 44,055 Points

There is more than one way to do it. You could try startswith() as explained here

Nils Kriedner
Nils Kriedner
17,071 Points

Have not tried it in the code challenge but very probably would not work because the challenge explicitly asks for an if-statement + the course teaches accessing the letters in a string with the [].

Daron Anderson
Daron Anderson
1,967 Points

I love the design of your website. @kris Nikolaisen. Is your methodology, "If it works it works?"

Nils Kriedner
Nils Kriedner
17,071 Points

Hi Daron,

you need to use an IF statement before the print command in this second task of the challenge.

So... IF the first letter of the word is equal to "A" then - next line - print etc.

To check the first letter you need to index the first letter of the string.

Does that help a bit? Otherwhise I could write more tomorrow, need to go to bed now...

Happy coding!

Nils

Daron Anderson
Daron Anderson
1,967 Points

@Nils Kriedner Where does it ask for the if staement?

Nils Kriedner
Nils Kriedner
17,071 Points

HI Daron,

just checked where I saw it and I can't find it.

Either I was halluzinating ;-) or I mixed it up with some other challenge (which is highly likely).

So sorry about claiming something without checking it up again. I was so sure I had read it in that challenges text.

Anyhow, you can definetely solve the challenge with an if statement, that's for sure. I just checked it.

Could you solve it in the meanwhile?

Nils

Daron Anderson
Daron Anderson
1,967 Points

Nils Kriedner I feel it I mix my syntax up with other languages sometimes.