Lists in Python: wrong answer in quiz

The link : https://www.codecademy.com/paths/analyze-data-with-python/tracks/ida-2-introduction-to-python/modules/ida-2-3-python-lists/quizzes/create-python-list-quiz

the question is “How could we add ['Hawaii', 'Alaska'] to the list states ?” but first answer is not actually add ['Hawaii', 'Alaska'] to states it returns new list but does not assigns to states. The third answer is right answer because it adds ['Hawaii', 'Alaska'] to states. Plz fix this bug :slight_smile:

1 Like

Hello, @eunsukimme.

You can only use .append(value) to add a single value to a list. The first answer is also not quite correct. As you stated:

The first answer would be correct if it read: states += ['Hawaii', 'Alaska']

Nice job noticing the mistake!

6 Likes

thank you @midlindner :slight_smile: i understanded!

1 Like

I submitted a bug report to Codecademy via a portal accessible by only moderators and SU’s. Hopefully they’ll correct it. Thanks again for pointing it out!

1 Like

Should be fixed now. They jumped on it really fast.

1 Like

It still seems a bit confusing that it would tell you states.append(['Hawaii', 'Alaska']) is wrong with an error message saying “we can only add one item at a time using append” because this code would work and is only appending one item which would be the list ["Hawaii", "Alaska"]

I think the correct answer would be more clear and the error message would make sense if that line was changed to states.append('Hawaii", "Alaska')

Would append the list as a single element of the existing states list.
For example:

states = ['Texas', 'Wisconsin']
states.append(['Hawaii', 'Alaska'])
print(states)

Output:

[‘Texas’, ‘Wisconsin’, [‘Hawaii’, ‘Alaska’]]

That’s right, but look at the image that was originally posted again.

So the answer he chose for this question was states.append(['Hawaii', 'Alaska']). As you pointed out it would append the list as a single element to the existing states list. The error message its giving at the bottom to explain why this answer is wrong says “we can only add one item at a time using append”, which is implying that answer is wrong because you are trying to use append to add multiple elements at the same time to the existing list, which is not the case, and leads me to beleive that answer was originally meant to be written as states.append('Hawaii", "Alaska') but a mistake was made.

Okay. I see what you are saying. The error message is technically inaccurate. The Codecademy Bug Fixing Team is going to get tired of hearing from me if they aren’t already. Oh well. As the saying goes, “If it’s not worth doing right, it’s not worth doing.” :slightly_smiling_face:

I’ll suggest they either change the error message to, “This would create a nested list.” Or that they change the answer as you’ve suggested to:

Thanks for being so observant!

4 Likes

Happy to help!

As I mentioned before I think changing the answer would be best to make the correct answer clear, just because of how the question is written out. I believe the intent of the question is clear but if you happened to take it very literally as asking “How can we add the list ['Hawaii', 'Alaska'] to the list states?” then technically the correct answer is actually states.append(['Hawaii', 'Alaska'])

4 Likes

That was painless. Should be fixed now. :slightly_smiling_face:

Edit:
And so it is:

2 Likes