Untitled

 avatar
unknown
plain_text
15 days ago
1.2 kB
6
Indexable
class House:
    parts = [
        "the house that jack built",
        "the malt that lay in",
        "the rat that ate",
        "the cat that killed",
        "the dog that worried",
        "the cow with the crumpled horn that tossed",
        "the maiden all forlorn that milked",
        "the man all tattered and torn that kissed",
        "the priest all shaven and shorn that married",
        "the rooster that crowed in the morn that woke",
        "the farmer sowing his corn that kept",
        "the horse and the hound and the horn that belonged to",
    ]

    def recite(self, max_lines=None, end_punctuation=".", blank_lines=1) -> str:

        if max_lines is None:
            max_lines = len(self.parts)

        results = []

        for i in range(max_lines):
            verse = "This is "

            for j in range(i, -1, -1):
                if j == i:
                    verse += self.parts[j]
                else:
                    verse += "\n" + self.parts[j]

            verse += end_punctuation
            results.append(verse)

        separator = "\n" * (blank_lines + 1)
        return separator.join(results)


print(House().recite())
Leave a Comment