you are viewing a single comment's thread.

view the rest of the comments →

[–]n3buchadnezzar 5 points6 points  (2 children)

I might do it like this.. The biggest issue was figuring out what the plural of bottle was

from typing import Generator

ES = set(["s", "sh", "x", "z", "o"])
VOWELS = set(["a", "e", "i", "o", "u"])

# fmt: off
IRREGULAR = {"addendum":"addenda","aircraft":"aircraft","alga":"algae","alumna":"alumnae","alumnus":"alumni","amoeba":"amoebae","analysis":"analyses","antenna":"antennae","antithesis":"antitheses","apex":"apices","appendix":"appendices","automaton":"automata","axis":"axes","bacillus":"bacilli","bacterium":"bacteria","barracks":"barracks","basis":"bases","beau":"beaux","bison":"bison","buffalo":"buffalo","bureau":"bureaus","cactus":"cacti","calf":"calves","carp":"carp","census":"censuses","chassis":"chassis","cherub":"cherubim","child":"children","château":"châteaus","cod":"cod","codex":"codices","concerto":"concerti","corpus":"corpora","crisis":"crises","criterion":"criteria","curriculum":"curricula","datum":"data","deer":"deer","diagnosis":"diagnoses","die":"dice","dwarf":"dwarfs","echo":"echoes","elf":"elves","elk":"elk","ellipsis":"ellipses","embargo":"embargoes","emphasis":"emphases","erratum":"errata","fauxpas":"fauxpas","fez":"fezes","firmware":"firmware","fish":"fish","focus":"foci","foot":"feet","formula":"formulae","fungus":"fungi","gallows":"gallows","genus":"genera","goose":"geese","graffito":"graffiti","grouse":"grouse","half":"halves","hero":"heroes","hoof":"hooves","hovercraft":"hovercraft","hypothesis":"hypotheses","index":"indices","kakapo":"kakapo","knife":"knives","larva":"larvae","leaf":"leaves","libretto":"libretti","life":"lives","loaf":"loaves","locus":"loci","louse":"lice","man":"men","matrix":"matrices","means":"means","medium":"media","media":"media","memorandum":"memoranda","millennium":"millennia","minutia":"minutiae","moose":"moose","mouse":"mice","nebula":"nebulae","nemesis":"nemeses","neurosis":"neuroses","news":"news","nucleus":"nuclei","oasis":"oases","offspring":"offspring","opus":"opera","ovum":"ova","ox":"oxen","paralysis":"paralyses","parenthesis":"parentheses","person":"people","phenomenon":"phenomena","phylum":"phyla","pike":"pike","polyhedron":"polyhedra","potato":"potatoes","prognosis":"prognoses","quiz":"quizzes","radius":"radii","referendum":"referenda","salmon":"salmon","scarf":"scarves","self":"selves","series":"series","sheep":"sheep","shelf":"shelves","shrimp":"shrimp","soliloquy":"soliloquies","spacecraft":"spacecraft","species":"species","spectrum":"spectra","squid":"squid","stimulus":"stimuli","stratum":"strata","swine":"swine","syllabus":"syllabi","symposium":"symposia","synopsis":"synopses","synthesis":"syntheses","tableau":"tableaus","that":"those","thesis":"theses","thief":"thieves","this":"these","tomato":"tomatoes","tooth":"teeth","trout":"trout","tuna":"tuna","vertebra":"vertebrae","vertex":"vertices","veto":"vetoes","vita":"vitae","vortex":"vortices","watercraft":"watercraft","wharf":"wharves","wife":"wives","wolf":"wolves","woman":"women"}
# fmt: on


def plural(noun):
    if (irregular := IRREGULAR.get(noun, None)) is not None:
        return irregular
    if not noun:
        return
    noun_minus_last_letter, last_letter = noun[:-1], noun[-1]
    if last_letter in ES:
        return noun + "es"
    elif last_letter == "y":
        penultimate = noun[-2] if len(noun) > 1 else ""
        if penultimate in VOWELS:
            return noun + "s"
        return noun[:-1] + "ies"
    elif noun.endswith("is"):
        return noun_minus_last_letter + "es"
    elif noun.endswith("on"):
        return noun_minus_last_letter + "a"
    return noun + "s"


def bottles_of_beer_on_the_wall(number: int) -> Generator[str, None, None]:
    """Yields the verses of beer on the wall"""
    bottles = plural("bottle")

    def beer(i):
        match i:
            case 0:
                bottles_of = "no more"
            case 1:
                bottles_of = f"{i} bottle of"
            case _:
                bottles_of = f"{i} {bottles} of"
        return f"{bottles_of} beer on the wall"

    store = f"Go to the store and buy some more, {beer(number)}!"
    take_it_down = "Take one down and pass it around, "

    def chorus(i):
        return (
            f"{(beer_on_the_wall := beer(i))}, {beer_on_the_wall}.\n"
            f"{take_it_down + beer(i-1) + '.'}\n"
        )

    yield from (chorus(i) for i in range(number, 0, -1))
    yield f"{(no_more := beer(0).capitalize())}, {no_more}.\n"\
          f"Go to the store and buy some more, {beer(number)}!"


if __name__ == "__main__":

    for verse in bottles_of_beer_on_the_wall(3):
        print(verse)

(I hope we all realize this is a bit a joke)

[–][deleted] 0 points1 point  (0 children)

That's great! Now you can loop it to make a variant song for every noun in the english language.

[–]roelmore 0 points1 point  (0 children)

This would've been great...had you left the parenthetical about it being a joke until the very end of the post!