Python Madlibs


I can't figure out what wrong.

print "Mab Libs is starting!"

name = raw_input("Enter a name: ")
first_adj = raw_input("Enter an adjective: ")
second_adj = raw_input("Enter another ajdective: ")
third_adj = raw_input("Enter a final adjective: ")

first_verb = raw_input("Enter a verb: ")
second_verb = raw_input("Enter another verb: ")
third_verb = raw_input("Enter a final verb: ")

first_noun = raw_input("Enter a noun: ")
second_noun = raw_input("Enter another noun: ")
third_noun = raw_input("Enter another noun: ")
fourth_noun = raw_input("Enter a final noun:")

animal = raw_input("Enter an animal: ")
food = raw_input("Enter a food: ")
fruit = raw_input("Enter a fruit: ")
number = raw_input("Enter a number: ")
superhero_name = raw_input("Enter a superhero name: ")
country = raw_input("Enter a country: ")
dessert = raw_input("Enter a dessert: ")
year = raw_input("Enter a year: ")

The template for the story

STORY = "This morning I woke up and felt % because %s was going to finally %s over the big %s %s. On the other side of the %s were many %ss protesting to keep %s in stores. The crowd began to %s to the rythym of the %s, which made all of the %ss very %s. %s tried to %s into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping %s into a puddle of %s. %s then fell asleep and woke up in the year %s, in a world where %ss ruled the world."

print STORY % (first_adj, name, first_verb, second_adj, first_noun, second_noun, animal, food, second_verb, third_noun, fruit, third_adj, name, third_verb, number, name, superhero_name, superhero_name, name, country, name, dessert, name, year, fourth_noun)


I fixed the "%ss"

(erkjnergjnerngjknserkjgnjenrjnjnerjngjnejrngjnejrnjnerg) <-- nevermind this


Missing an s here.

You don't need to store this into a variable at all.

I highly suggest you review this kind of string formatting.
An example of one is this:

name = raw_input("Enter a name: ")

print "Good day to you, %s" % (name,)

Notice I didn't need to store this in a variable and the syntax of it.

Side note: The %s method is ok but str.format method is more powerful.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.