Making Sentences (and poems) with Python




The goal for this activity is to make a program that generates English sentences. You will try to make a program write a poem. You will do this by creating a set of grammar rules and word lists, and then a program that uses these to generate a poem from randomly selected words.

Am essential requirement is that you break you program up into a set of functions the each perform a specific function, and that work together to generate a poem.


Consider the following code:


1. Experiment with at least five different sentence structures. English has plenty.

  • Can you write a rule for a passive sentence, e.g.:
    1. The student was using her phone. (Active)
    2. The phone was being used by the student. (passive)
  • Can you find a way to deal with verb agreement, e.g.:
    1. The woman swims for the finish line. (singular subject)
    2. The four woman swim for the finish line. (plural subject)
  • Can you write a rule with an embedded clause?
    1. The girl watched the puppies playing in the yard. (Active)
    2. The puppies playing in the yard were watched by the girl. (Passive)
For each sentence structure write a difference function to generate that type of sentence. The function should return a sentence as a string.

2. Pick a poetry style, or make one up, and make a program that generates that type of poem. You can pick words that represent a domain that you wish the poems to focus on.


Traditional Haiku Structure

Traditional haiku are always the same, including the following features:

  1. There are only three lines, totaling 17 syllables.
  2. The first line is 5 syllables.
  3. The second line is 7 syllables.
  4. The third line is 5 syllables like the first.
  5. Punctuation and capitalization are up to the poet, and need not follow rigid rules used in structuring sentences.
  6. A haiku does not have to rhyme, in fact usually it does not rhyme at all.
  7. Some haiku can include the repetition of words or sounds
Over the wintry forest,
winds howl in rage
with no leaves to blow.


  1. Limerick
  2. Types of Poems
  3. Introduction to Types of Poems
3. Write a program that on command generates a poem. You can make any type of poem you want, even you own invention.

4. Added features: Add at least two.
  • The program asks the user for words
  • The program keeps track of words used, like nouns chosen, so that a group of sentences are tied together by a common topic.
  • The program gives the option of saving a poem to a file after generating it.
  • The program gets its word lists from a file(s). You can get word lists from many sources on line: Example.
  • Something else you propose.
Topic attachments
I Attachment History Action Size Date Who Comment
PNGpng images.png r1 manage 9.6 K 2018-10-08 - 02:16 JimSkon  
Edit | Attach | Watch | Print version | History: r9 < r8 < r7 < r6 < r5 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r9 - 2019-10-15 - JimSkon
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2020 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback