Difference between revisions of "CSC111 Homework 5 2014"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <bluebox> This assignment is due at midnight on Thursday, 3/6/14 at midnight. You can work on it individually or work in pair. You are free to pick your partner ...")
 
Line 1: Line 1:
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 22:04, 25 February 2014 (EST)
+
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 22:05, 25 February 2014 (EST)
 
----
 
----
 
<bluebox>
 
<bluebox>

Revision as of 23:05, 25 February 2014

--D. Thiebaut (talk) 22:05, 25 February 2014 (EST)


This assignment is due at midnight on Thursday, 3/6/14 at midnight. You can work on it individually or work in pair. You are free to pick your partner if you decide to work in pair, in which case you should make sure that both names and 2-letter Id appear in the header of your program.





Problem #1: Random poems

This problem touches on many different Python constructs we have seen so far. It is more for fun that a real challenge.

Run the following program that will remind you of the Rock, Scissors, Paper game in the way it uses a random animal.

# hw5a.py
# firstName lastName
# this program prints a random word every time it is run
#
from random import choice

# create a list of animals
farm = [ "pig", "cat", "dog", "horse", "donkey", "monkey", "snake", "fly" ]

# figure out how many animals are on the farm
animal = choice( farm )

# select the animal at that index and print its name
print "the", animal, "lives on the farm"


Create this program with Idle. Observe that every time you run it, the output is unpredictable.

Using this facility, write a program that creates random poems. In our case, a poem will be just one line long, and will contain a subject, an adverb, a verb, a location, and a time. We'll see an example very shortly that will clarify this idea.

Assume that we have a list of subjects, a list of adverbs, a list of verbs, a list of locations, and a list of times, as follows:

     subjects  = [ "The cat", "Cathy", "Oprah", "Paris Hilton" ]
     adverbs   = [ "never", "sometimes", "usually", "amazingly", "voraciously" ]
     verbs     = [ "likes to sleep", "eats mice", "runs" ]
     locations = [ "around the pond", "on the sofa", "in Duckett" ]
     times     = [ "at night", "early in the morning", "every Sunday afternoon", "whenever possible" ]


If we pick a random word from each list and "glue" all the words together, we end up with a one-line poem. For example Paris Hilton amazingly eats mice in Duckett House every Sunday afternoon.

Your assignment is to write a program that declares a different series of lists (lists should not have the same number of words), and asks the user how many one-line poems she would like to see. Your program will then print that many different poems.

Here is an example of how your program should work (the user input is underlined):


Welcome to the Random Poems of the Day! 
How many poems would you like me to generate for you? 3

Here are your 3 poems:

Paris Hilton amazingly eats mice in Duckett every Sunday afternoon
The cat never runs on the sofa early in the morning
Mrs Christ sometimes runs on the sofa at night

Use your imagination when you create the lists of words, please!

Requirements


If the user enters a number that is 0 or negative it will keep on prompting the user, and will accept only integers greater than 0.

Submission


Store your program in a file called hw5a.py and submit it to this URL: http://cs.smith.edu/~dthiebaut/111b/submit5.php