[FIXED] Error in Python 3 loop quiz?

None of the answers is the correct one, the quotes (") are not printed together with the elements.

The expected output would be coffee tea water juice soda (in reality one line per element).

Some other quizes space them like above instead of showing them on newlines.
Regardless this quiz answer is wrong.

➜  ~ python
Python 3.8.5 (default, Jul 27 2020, 08:42:51) 
[GCC 10.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> drink_choices = ["coffee", "tea", "water", "juice", "soda"]
>>> for drink in drink_choices:
...   print(drink)

I am uncertain if this is actually an error, I believe it is done this way so that they can fit everything on a single line, and the quotation marks are to designate that it is a string.

It doesn’t ask “what was printed to the console”, it asked “what is the output”. I will certainly ask about it though.

The exam is following it’s own conventions. It’s a pedagogical choice, which I think is ok.

Quotes to explicitly refer to strings, and no quotes refer to variable/object names.

They have to follow some convention, otherwise there’d be some contradictions like:

What’s the output of this? (when it’s variable names instead of strings)

drink_choices = [coffee, tea, water, juice, soda]
for drink in drink_choices:

The test answer would be

coffee tea water juice soda

If they didn’t use quotations for their example, this one would fall apart, as there’s no way to contrast it.

Alternatively they could use # comments to clarify type and all that. Hmm, but maybe that would be more clumsy.


You can force quotes to be displayed in the output by formatting drink variable with f-string:

drink_choices = ["coffee", "tea", "water", "juice", "soda"]
for drink in drink_choices:
1 Like

I’d have to agree with you, @jonher937. None of those are correct. We are left to choose the least incorrect answer. If they didn’t have room enough for the correct answer, they probably should have asked a different question.


f-strings have not been covered at that point, strings is the chapter after loops.
Also your example would produce single quotes and not double quotes

It’s already quoted in the list (so the value is a string).

Adding quotes around the output that is not actually there is not pedagogical, it’s incorrect.

The section before loops is lists, so this should already be clear from doing the Lists chapter.

1 Like

For me it’s just inaccurate. I wouldn’t write it like that. Literally, it is 100% wrong. What I meant by the pedagogical note is that they may be trying to highlight this type of stuff (hence why I still there’s some degree of a point trying to be made, again, in a clumsy way):


>>>for i in drink_choices:
>>>    "coffee" in i

But I agree that it’s not accurate. Moreover, many of their other exams don’t have a problem using multiple lines in the answer, so it’s not a hard fix.

Again to clarify, my thinking it’s a pedagogical choice doesn’t mean I think it’s a pedagogical choice well-delivered upon. What I meant about it being ok, is that I think it’s ok to make pedagogical choices (but it defeats the purpose if the clarity is muddied up).

Since it has been agreed on as a bug, could you post a link to the quiz so I can report it?

Sure, here it is: https://www.codecademy.com/courses/learn-python-3/quizzes/python-loops

The other questions in the quiz that should also contain newlines are just separated by space like this:

F-strings is not taught at Codecademy at all. I just wanted to show that there is a better way of manipulating strings then what they teach here. I guess I got too excited and posted the code example without completely thinking about it. I am sorry about that. But it does not change the fact that there is a better way to format strings then the methods covered by Codecademy. When you study Strings, you will learn about escaping similar characters and what to do if you do not want to use it. These two code examples will demonstrate these two concepts.

drink_choices = ["coffee", "tea", "water", "juice", "soda"]
for drink in drink_choices:

or you can do this without using escape characters:

drink_choices = ["coffee", "tea", "water", "juice", "soda"]
for drink in drink_choices:

I hope you will find this info useful. And good luck in your studies.

1 Like

F-strings are fairly new (relatively speaking) which I guess is why they aren’t covered. I do find myself using .format from time to time when it reads easier but bigging up f-strings certainly isn’t a bad thing. I think both are worth knowing.

1 Like

Especially when they do not have to anything extreme, like upgrading underlying python version, in order to teach f-string. They already running compatible Python version 3.6.7. And you right that it worth knowing both methods. The biggest con with f-strings is that they will not work with empty curly brackets and .format will.

I just reported it! Thanks for posting this!

1 Like

I don’t understand how that’s a con. What would be the point of placing empty curly braces in an f-string? Perhaps a better way to ask would be why would you want or need to put empty curly braces in an f-string?

1 Like

The error has been corrected!! :slightly_smiling_face:

1 Like