|
| 1 | +""" |
| 2 | +Bottle Song |
| 3 | +=========== |
| 4 | +
|
| 5 | +Recite verses from the children's song "Ten Green Bottles". |
| 6 | +
|
| 7 | +This module exposes the precomputed lyrics and a helper to |
| 8 | +extract slices of the song by verse. |
| 9 | +""" |
| 10 | + |
| 11 | +Ten_Green_Bottles: list[str] = [ |
| 12 | + "Ten green bottles hanging on the wall,", |
| 13 | + "Ten green bottles hanging on the wall,", |
| 14 | + "And if one green bottle should accidentally fall,", |
| 15 | + "There'll be nine green bottles hanging on the wall.", |
| 16 | + "", |
| 17 | + "Nine green bottles hanging on the wall,", |
| 18 | + "Nine green bottles hanging on the wall,", |
| 19 | + "And if one green bottle should accidentally fall,", |
| 20 | + "There'll be eight green bottles hanging on the wall.", |
| 21 | + "", |
| 22 | + "Eight green bottles hanging on the wall,", |
| 23 | + "Eight green bottles hanging on the wall,", |
| 24 | + "And if one green bottle should accidentally fall,", |
| 25 | + "There'll be seven green bottles hanging on the wall.", |
| 26 | + "", |
| 27 | + "Seven green bottles hanging on the wall,", |
| 28 | + "Seven green bottles hanging on the wall,", |
| 29 | + "And if one green bottle should accidentally fall,", |
| 30 | + "There'll be six green bottles hanging on the wall.", |
| 31 | + "", |
| 32 | + "Six green bottles hanging on the wall,", |
| 33 | + "Six green bottles hanging on the wall,", |
| 34 | + "And if one green bottle should accidentally fall,", |
| 35 | + "There'll be five green bottles hanging on the wall.", |
| 36 | + "", |
| 37 | + "Five green bottles hanging on the wall,", |
| 38 | + "Five green bottles hanging on the wall,", |
| 39 | + "And if one green bottle should accidentally fall,", |
| 40 | + "There'll be four green bottles hanging on the wall.", |
| 41 | + "", |
| 42 | + "Four green bottles hanging on the wall,", |
| 43 | + "Four green bottles hanging on the wall,", |
| 44 | + "And if one green bottle should accidentally fall,", |
| 45 | + "There'll be three green bottles hanging on the wall.", |
| 46 | + "", |
| 47 | + "Three green bottles hanging on the wall,", |
| 48 | + "Three green bottles hanging on the wall,", |
| 49 | + "And if one green bottle should accidentally fall,", |
| 50 | + "There'll be two green bottles hanging on the wall.", |
| 51 | + "", |
| 52 | + "Two green bottles hanging on the wall,", |
| 53 | + "Two green bottles hanging on the wall,", |
| 54 | + "And if one green bottle should accidentally fall,", |
| 55 | + "There'll be one green bottle hanging on the wall.", |
| 56 | + "", |
| 57 | + "One green bottle hanging on the wall,", |
| 58 | + "One green bottle hanging on the wall,", |
| 59 | + "And if one green bottle should accidentally fall,", |
| 60 | + "There'll be no green bottles hanging on the wall.", |
| 61 | +] |
| 62 | + |
| 63 | + |
| 64 | +def recite(start: int, take: int = 1) -> list[str]: |
| 65 | + """ |
| 66 | + Return a slice of the song lyrics corresponding to ``take`` consecutive |
| 67 | + verses starting from the verse that begins with ``start`` green bottles. |
| 68 | +
|
| 69 | + The lyrics are stored as a flat list where each verse occupies five lines |
| 70 | + (four lyric lines plus a trailing blank line). This function computes the |
| 71 | + appropriate slice boundaries to return the requested verses in order. |
| 72 | +
|
| 73 | + :param start: The number of green bottles to start from (e.g., 10 for |
| 74 | + "Ten green bottles"). Must be between 1 and 10. |
| 75 | + :param take: Number of consecutive verses to include starting at ``start``. |
| 76 | + Defaults to 1. |
| 77 | + :returns: A list of lyric lines forming the requested verses. |
| 78 | + """ |
| 79 | + start: int = -(start * 5) |
| 80 | + end: int = len(Ten_Green_Bottles) + start + (take * 5) |
| 81 | + return Ten_Green_Bottles[start + 1 : end] |
0 commit comments