| 1 | 1 | def recite(start: int, take: int = 1) -> list[str]: |
| 2 | | pass |
| 2 | verses = [] |
| 3 | |
| 4 | # Edge Case: take is zero, return empty list |
| 5 | if take == 0: |
| 6 | return [] |
| 7 | |
| 8 | # Edge Case: start is negative, treat as zero |
| 9 | if start < 0: |
| 10 | start = 0 |
| 11 | |
| 12 | # Edge Case: start + take exceeds 99, cap at 99 |
| 13 | if start > 99: |
| 14 | start = 99 |
| 15 | |
| 16 | for i in range(take): |
| 17 | current = start - i |
| 18 | |
| 19 | # Edge Case: current number goes below 0 |
| 20 | if current < 0: |
| 21 | break |
| 22 | |
| 23 | # Handle the special case for 0 bottles |
| 24 | if current == 0: |
| 25 | line1 = "No more bottles of beer on the wall, no more bottles of beer." |
| 26 | line2 = "Go to the store and buy some more, 99 bottles of beer on the wall." |
| 27 | verses.extend([line1, line2]) |
| 28 | # Handle the special case for 1 bottle |
| 29 | elif current == 1: |
| 30 | line1 = "1 bottle of beer on the wall, 1 bottle of beer." |
| 31 | line2 = "Take it down and pass it around, no more bottles of beer on the wall." |
| 32 | verses.extend([line1, line2]) |
| 33 | # Handle the special case for 2 bottles |
| 34 | elif current == 2: |
| 35 | line1 = "2 bottles of beer on the wall, 2 bottles of beer." |
| 36 | line2 = "Take one down and pass it around, 1 bottle of beer on the wall." |
| 37 | verses.extend([line1, line2]) |
| 38 | # General case for more than 2 bottles |
| 39 | else: |
| 40 | line1 = f"{current} bottles of beer on the wall, {current} bottles of beer." |
| 41 | line2 = f"Take one down and pass it around, {current - 1} bottles of beer on the wall." |
| 42 | verses.extend([line1, line2]) |
| 43 | |
| 44 | # Add empty line between verses, but not after the last verse |
| 45 | if i < take - 1 and current > 0: |
| 46 | verses.append("") |
| 47 | |
| 48 | return verses |
| 49 | |
| 50 | # Handled Edge Cases: take is zero, start is negative, start exceeds 99, current number goes below 0 |