99 bottles of beer: Difference between revisions

m
Line 6,956:
=={{header|Python}}==
===Python 3, a readable version===
Most people solving this task iterate from 99 to 0. But 2, 1 and 0 are special cases, therefore they write conditional expressions to split flow control. Anyway the "if" instruction is unnecessary at all. The special casecases could be excluded as separate block outside loop. TheA "busisness logic" to write bottle/bottles (and to recognize that 0 bottles should be "no more") would be not so simple to code. ATherefore a copy-paste of the last three verses of the song is much more KISS. It is enough to focus on the first 97 verses to achieve essential savings.
<lang Python>
"""Pythonic 99 beer song (readability counts)."""
 
regular_verseregular_verses = '''\
{n} bottles of beer on the wall, {n} bottles of beer
Take one down and pass it around, {n_minus_1} bottles of beer on the wall.
Line 6,984:
 
for n in range(99, 2, -1):
print(regular_verseregular_verses.format(n=n, n_minus_1=n - 1))
print(ending_verses)</lang>