Mad Libs problem Part two project


Hey just started coding, I have no background in this and I don't really have the terminology down yet.

When I try to run my code all the raw_inputs seem to work fine, my problem starts when the words are trying to be added to the story. How do I define the STORY.

Error message I get in my terminal:
Traceback (most recent call last):
File "", line 23, in
print STORY %(adj1,name,verb1,adj2,noun1,
noun2,animal,food, verb2,noun3,fruit,adj3,nam
e,verb3,number,name, hero,hero,name,country,n
ame,dessert,name,year, noun4)
NameError: name 'STORY' is not defined

I used # to create the mesaage at the top when I know you are suppose to use the """ but in the program the every time I use that symbol the program doubles it. Weird?

#Lets see if you can fill in the blanks and make a funny story using your imagination. This ia a madlib. Good Luck!
#Author: Annah G
print "Ready? Here we Go"
name=raw_input("Enter a name:")
adj1=raw_input("Enter an adjective:")
adj2=raw_input("Enter an adjective:")
adj3=raw_input("Enter an adjective:")
verb1=raw_input("Please select a verb:")
verb2=raw_input("Enter a new verb:")
verb3=raw_input("Enter final verb:")
noun1=raw_input("Select a noun:")
noun2=raw_input("Enter an new noun:")
noun3=raw_input("Enter another noun:")
noun4=raw_input("Last 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:")
hero=raw_input("Enter a superheros name:")
country=raw_input("Enter the country you were born:")
dessert=raw_input("Enter your favorit dessert:")
year=raw_input("Enter year you were born:")
print STORY %(adj1,name,verb1,adj2,noun1,noun2,animal,food, verb2,noun3,fruit,adj3,name,verb3,number,name, hero,hero,name,country,name,dessert,name,year, noun4)
#The template for the story
STORY = "This morning I woke up and felt %s 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."


Hi, @agerletti ,

You did define STORY in the final statement in your program. However, it needs to be defined prior to the print statement, since that statement looks up the value of STORY in order to produce the output.

To remedy the problem, either move what is currently the final statement to a position prior to the print statement, or move the print statement so that it becomes the final statement in your program.


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