Python Introducing Lists Using Lists Continental

Enrica Fedeli-Jaques
Enrica Fedeli-Jaques
4,351 Points

List exercise not working, but weird

Hi, I get the weirdest message saying that the first item on the list isn't showing when it actually is. I wish I could attache a screenshot! anyone that can figure out why?

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

for continent in [0, 3, 5, 6]:
    print("*" + continents[continent])

2 Answers

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 50,936 Points

I think the solution is supposed to work for any list without having to specify indexes. If you had hundreds of entries would you be expected to manually find the index of each item that meets a condition? Or make the code do the work for you?

There is a hint in task 2: Remember that you can access characters in a string by index

For this you can use the syntax continent[0] to access the first character of continent. Then compare this to 'A' and if they match print the bulleted continent name. Below is probably the most common solution.

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

for continent in continents:
    if continent[0] == "A":
        print("*", continent)
Enrica Fedeli-Jaques
Enrica Fedeli-Jaques
4,351 Points

ahah I just went "OH! ... of course!" thank you so much! really appreciated!

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 50,936 Points

You get (partially) Bummer: AssertionError: '* Asia' not found in '*Asia

Notice the missing space between the bullet and the continent name. Although fixing that will pass the challenge I don't think what you have was intended as a solution. But if it works - why not?

Enrica Fedeli-Jaques
Enrica Fedeli-Jaques
4,351 Points

oh, you think? I wasn't 100% sure what the test meant, in fact. what do you think was I meant to do? thank you for your answer BTW :) oh, and also, I was at step two, you can't see step one in my code anymore