Python Introducing Lists Using Lists Continental

Justin Armstrong
Justin Armstrong
3,702 Points

Accessing characters in a string by index

I don't know what to do

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

print("Continents:")
for continent in continents:
    print("* " + continent)


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

3 Answers

bot .net
bot .net
12,822 Points

You're very close. read the instructions again, don't do things that u didn't been asked to do.

Barry Snowe
Barry Snowe
47,676 Points

Two things to note:

  1. It looks like you got part one of the challenge right. But you started challenge 2 with another for loop, which is not necessary. Everything should happen in the one for loop you wrote (you just need to revise it to do the new task as well...)

  2. The new task is asking you to be selective as to what you are printing out. When we are selective, we use a decision structure. A for loop is a control structure (i.e. controlling the flow of traffic, so to speak). So what kind of command provides a "decision" structure? As in "I will choose this one thing IF this other thing happens"...?

Also, remember that strings can be treated like "lists" of characters. Think about that when you zero in on that first letter.

Justin Armstrong
Justin Armstrong
3,702 Points

I appreciate the responses, but I still need the answer with a detailed explanation....still confused

bot .net
bot .net
12,822 Points

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

Your code here

for x in continents: if x[0] == "A": print("* " + x) first u loop through the list, then u check if the current element in the list start with the letter A at index 0, if it is u print the current element