Python Haiku generator


Write a program that generates simple haiku poems according to these rules.

• Each line of the poem is a single sentence.

  • The first line and the third line will each be 5 syllables.
  • The second line will be 7 syllables.
  • Each line relates to the indicated theme.
  • Modify a copy of the file linuxwords.txt as follows:

    ª Choose at least 100 words of the file, including several words in each of these parts of speech: article (a, an, the), adjective other than article, noun, verb, an article. (It’s ok to include conjustions, prepositions, and pronouns, but that willl make your grammar larger.

    * Choose at least 3 themes (ex. autumn, food, weather).

  • For each word other than an article (or conjunction or prepositon or prounoun), add to the entry in your modified linuxwords.txt the number of syllables, a “part of speech,” and one of the three themes.
  • For example, you might have these entries:

    tree, 1, noun, autumn

    trees, 1, noun, autumn

    leaf, 1, noun, autumn

    leaves, 1, noun, autumn

    bonfire, 2, noun, autumn

    Halloween, 3, noun, autumn

    Halloween, 3, adjective, autumn

    see, 1, verb, autumn

    I, 1, article, autumn

    red, 1, adjective, autumm

    orange, 2, adjective, autumn

    From these words your progrm might generate the sentence:

    I see orange leaves.

    * Write at least three rules for sentences.

    For example, your rules might include:

    <sentence> ::= <pronoun> <verb> <adjective> <noun>

    <sentence> ::= <article> <adjective> <noun> <verb> <noun>

    * Your program should input a theme (“august” in this example) and generate at least five random hiakus.

    About the Author

    Follow me

    {"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}