99 bottles of beer: Difference between revisions
Content deleted Content added
Added implementation for 'fe' language |
Marco Sulla (talk | contribs) →One line: 1. bottle without s is optional (but you can add it easily); 2: the task does not mention the "canonical" text (anyway, you can add it easily); 3: the task does not says anything about PEP8 |
||
Line 10,179: | Line 10,179: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
===One line=== |
===One line=== |
||
{{Works with|Python|3.8}} |
{{Works with|Python|3.8+}} |
||
Short, one-line version. |
|||
<syntaxhighlight lang="python">for i in range(99, 0, -1): b |
<syntaxhighlight lang="python">for i in range(99, 0, -1): b='bottles of beer'; w = b + ' on the wall'; print(f'{i} {b} on the wall, {i} {b}\nTake one down and pass it around, {i - 1} {w}.\n') |
||
</syntaxhighlight> |
</syntaxhighlight> |
||
Unfortunately, '''it is not a good example''' of how to write in Python. The last verse is different than it should be. It should be (according to the canonical text) "Go to the store and buy some more, 99 bottles of beer on the wall". Moreover, the grammar is not correct: it always writes "bottles" even when there is one bottle. Another problem is the obvious violation of PEP8, see https://www.python.org/dev/peps/pep-0008. |
|||
{{output}} |
|||
To save space, some of the text was of course omitted. |
|||
<pre>99 bottles of beer on the wall, 99 bottles of beer |
|||
Take one down and pass it around, 98 bottles of beer on the wall. |
|||
98 bottles of beer on the wall, 98 bottles of beer |
|||
Take one down and pass it around, 97 bottles of beer on the wall. |
|||
... |
|||
3 bottles of beer on the wall, 3 bottles of beer |
|||
Take one down and pass it around, 2 bottles of beer on the wall. |
|||
2 bottles of beer on the wall, 2 bottles of beer |
|||
Take one down and pass it around, 1 bottles of beer on the wall. |
|||
1 bottles of beer on the wall, 1 bottles of beer |
|||
Take one down and pass it around, 0 bottles of beer on the wall. |
|||
</pre> |
|||
===PEP8 compilant=== |
===PEP8 compilant=== |