Another Update to my Mad Lib App

| | Comments (0) | TrackBacks (0)

My previous version of the mad lib app had a few problems. First of all, the story I wrote was terrible, and didn't even use all of the variables entered by the user. Related to that, I made it ask every question exactly three times, even though I didn't need three answers for each one. Furthermore, I wasn't very specific about the user input, and it didn't always work grammatically in my story. I've fixed all of that.


# Mad Lib
# madlib.rb
# Creates a mad lib based on user input

def ask part
input = gets.chomp.upcase
part.push input
end
verb = []
adj = []
obj = []
ly = []
job = []
puts 'Type in one verb, followed by a return:'
ask verb
puts 'Now, type in four adjectives, followed by return after each one:'
ask adj
ask adj
ask adj
ask adj
puts 'Now type in two everyday objects, followed by return after each one:'
ask obj
ask obj
puts 'Type in one adverb that ends in -ly:'
ask ly
puts 'Type in two job titles, such as "worker"'
ask job
ask job

puts 'One very ' +adj[0]+ ' day, a kind ' +job[0]+ ' went up to a ' +adj[1]
puts job[1]+ ' and asked to borrow some money to buy a ' +adj[2]+ ' ' +obj[0]+ ','
puts 'which he needed very badly. The ' +job[0]+ ' told him that he would lend'
puts 'the money only if the ' +job[1]+ ' would agree to ' +verb[0]+ ' a'
puts ly[0]+ ' ' +adj[3]+ ' ' +obj[1]+ '. The ' +job[0]+ ' decided it wasn\'t'
puts 'worth it.'

In my new version, I changed the user inputs to make them more specific. Instead of just asking for nouns, I ask for job titles and objects. Adverbs became an -ly adverb. The only place I see where it might not work out perfectly is if the adjectives start with vowel sounds, because the story has "a" before them, instead of "an." I could write a huge amount of code (probably equal to this entire program, as-is, if not more) just to account for this and automatically change the "a" to "an." I could also just ask people in the question to stick to consonants. But I don't think it really matters. It's a mad lib; "a orange tree" is to be expected.

The other issue is that by removing the code that automatically asks each question three times, I have to repeat the same lines of code for each time I want it asked. There are ways that I could code it so that I could pass it an additional variable—the number of times to ask the question—but my method is so short anyway (ask adj) that I don't think it would actually save any space.

Here is the code when run:


iMac:Ruby kirk$ Ruby madlib.rb
Type in one verb, followed by a return:
open
Now, type in four adjectives, followed by return after each one:
blue
clean
dirty
high
Now type in two everyday objects, followed by return after each one:
cup
phone
Type in one adverb that ends in -ly:
fetchingly
Type in two job titles, such as "worker"
serf
restaurateur
One very BLUE day, a kind SERF went up to a CLEAN
RESTAURATEUR and asked to borrow some money to buy a DIRTY CUP,
which he needed very badly. The SERF told him that he would lend
the money only if the RESTAURATEUR would agree to OPEN a
FETCHINGLY HIGH PHONE. The SERF decided it wasn't
worth it.

0 TrackBacks

Listed below are links to blogs that reference this entry: Another Update to my Mad Lib App.

TrackBack URL for this entry: http://kirk.luceo.net/mt/mt-tb.cgi/88

Leave a comment

About this Entry

This page contains a single entry by Kirk published on October 16, 2008 2:32 AM.

Age Quiz was the previous entry in this blog.

iPhone Programming is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.01