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)
...
coffee
tea
water
juice
soda
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.
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.
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):
>>>drink_choices[0]
'coffee'
>>>for i in drink_choices:
>>> "coffee" in i
True
False
False
False
False
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).
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:
print(f"\"{drink}\"")
or you can do this without using escape characters:
drink_choices = ["coffee", "tea", "water", "juice", "soda"]
for drink in drink_choices:
print(f'"{drink}"')
I hope you will find this info useful. And good luck in your studies.
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.
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 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?