Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Example Photographic MadLibs

Did you ever do MadLibs as a kid? You're asked to supply, say, a name, a food, a verb, and a place. Then the words you supply get plugged into the blanks of a story, with often bizarre and sometimes humorous results e.g., like "George W. Bush likes to snort largue chunks of chocolate while visiting The Louvre."

Here's an example of doing that same idea, but with pictures.

Here's the first version. The pictures "Mark.jpg","Barbara.jpg","beach.jpg", and "ken.jpg" were all put into the same directory where madlib.html was to be stored (in this example, right in the same directory as JES). I then called:
 madlib("Mark.jpg","Barbara.jpg","beach.jpg","ken.jpg")
And here's the result: madlib1.html

The fun part of madlib is to try different sets of words in the same story. So, here's the same story again, but plugging in:
 madlib("Mark.jpg","Bird.jpg","moon.jpg","horse.jpg")
madlib2.html

The Code

Here's the program that generates these: madlib.py

Notice that the input could be any valid URL – the pictures don't have to be on your disk at all!

How it works
  file=open("madlib.html","wt")
  person1='<image width=50 src="'+person1url+'">'
  person2='<image width=50 src="'+person2url+'">'
  place='<image width=100 src="'+placeurl+'">'
  otherperson='<image width=50 src="'+otherpersonurl+'">'
  file.write("<p>"+person1+" said to "+person2+'"I know this great place: '+place)
  file.write('Will you meet me there?"')

Link to this Page