Python Introducing Lists Using Lists Continental

Not sure why I'm getting an Assertion Error

My output is correct or at least it looks correct to me, but after the second time it was run, I'm getting a 'Assertion Error.'

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
for continent in [0, 1, 2, 3, 4, 5, 6]:
    print("* ", continents[continent])

5 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 56,908 Points

It's not obvious from the output, but comma-separated arguments to print() are output with a space between then. Since the first item includes a space in "* ", then effectively there are two spaces.

So I assume you just delete the white space and all is good?

Chris Freeman
Chris Freeman
Treehouse Moderator 56,908 Points

Correct. You can:

  • remove the white space
  • add the sep='', argument to print()
  • use a formatted string such as:
    • f"* {continent}"
    • "* {}.format(continent)"`
    • "* %s" % continent

My apologies, Chris! I must have clicked it by accident.

u"\U0001F44D"

Chris Freeman
Chris Freeman
Treehouse Moderator 56,908 Points

Treehouse allows markup for "thumbs up". Using ":thumbsup:" or ":+1:" ==> :thumbsup:

Manuel Canario
Manuel Canario
624 Points

I am really lost, this is the way I did it, however, I have not found any instructions on the "f" function uses.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here

for continent in continents:
    if  continent(0) == 'A':
    print("* "+ continent)
Chris Freeman
Chris Freeman
Treehouse Moderator 56,908 Points

Very close. continent isn’t a function which is what the parens imply. Use continent[0] instead.