Python 2; exercise 7/12; Madlibs

https://www.codecademy.com/courses/learn-python/projects/madlibs-1

Hello, I have recently started, and currently I am facing a type error issue on bash; exercise 7/12; Madlibs.

File “Madlibs.py”, line 26, in
print STORY % (name, adjective1, adjec
tive2, adjective3, verb, noun1, noun2, ani
mal, food, fruit, superhero, country, dess
ert, year)
TypeError: not enough arguments for format
string

My code as below:

# The template for the story

STORY = "This morning %s woke up feeling %s. 'It is going to be a %s day!' Outside, a bunch of %ss were protesting to keep %s in stores. They began to %s to the rhythm of the %s, which made all the %ss very %s. Concerned, %s texted %s, who flew %s to %s and dropped %s in a puddle of frozen %s. %s woke up in the year %s, in a world where %ss ruled the world."

print "madlibs is starting"

name = raw_input("Enter a name ")

adjective1 = raw_input ("Enter an adjective: ")

adjective2 = raw_input ("Enter an adjective: ")

adjective3 = raw_input ("Enter an adjective: ")

verb = raw_input ("Enter a verb: ")

noun1 = raw_input ("Enter a noun: ")

noun2 = raw_input ("Enter a noun: ")

animal = raw_input ("Enter an animal: ")

food = raw_input ("Enter a food: ")

fruit = raw_input ("Enter a fruit: ")

superhero = raw_input ("Enter a superhero: ")

country = raw_input ("Enter a country: ")

dessert = raw_input ("Enter a dessert: ")

year = raw_input ("Enter a year: ")

print STORY % (name, adjective1, adjective2, adjective3, verb, noun1, noun2, animal, food, fruit, superhero, country, dessert, year)

Hello, @devrockstar94813, and welcome to the Codecademy community!

Count the number of % format specifiers in STORY. Make sure that it matches, exactly, the number of variables within the tuple in your final line of code.

1 Like

Thank you.
I have updated the code:

The template for the story

STORY = “This morning %s woke up feeling %s. ‘It is going to be a %s day!’ Outside, a bunch of %ss were protesting to keep %s in stores. They began to %s to the rhythm of the %s, which made all the %ss very %s. Concerned, %s texted %s, who flew %s to %s and dropped %s in a puddle of frozen %s. %s woke up in the year %s, in a world where %ss ruled the world.”

print “madlibs is starting”

name = raw_input("Enter a name ")

adjective1 = raw_input ("Enter an adjective: ")
adjective2 = raw_input ("Enter an adjective: ")
adjective3 = raw_input ("Enter an adjective: ")

verb = raw_input ("Enter a verb: ")

noun1 = raw_input ("Enter a noun: ")
noun2 = raw_input ("Enter a noun: ")

animal = raw_input ("Enter an animal: ")
food = raw_input ("Enter a food: ")
fruit = raw_input ("Enter a fruit: ")
superhero = raw_input ("Enter a superhero: ")
country = raw_input ("Enter a country: ")
dessert = raw_input ("Enter a dessert: ")
year1 = raw_input ("Enter a year: ")
year2 = raw_input ("Enter a year: ")
year3 = raw_input ("Enter a year: ")
year4 = raw_input ("Enter a year: ")
year5 = raw_input ("Enter a year: ")

print STORY % (name, adjective1, adjective2, adjective3, verb, noun1, noun2, animal, food, fruit, superhero, country, dessert, year1, year2, year3, year4, year5)

And bash has now accepted it (I know, it is not ideal code, but I was just tinkering around), but it does the job. Now, however, I cannot click the “up next” button.

Note that instruction 11 specifies what information should be placed in the tuple, in the order in which it should occur. The problem with your original code was that name was expected to appear in there a total of five times, but you only had one occurrence of it. With name there five times in the appropriate places, the number of occurrences of variables would match the number of %s format specifiers.

1 Like

Hello, Thank you again for your kind assistance.
I have redone my code, which contains 18 variables. Now the issue I am finding is that once I enter the answer to the final variable in Terminal, I just get a $ sign, and the story doesn’t appear.

name = raw_input("Enter a name ")

adjective1 = raw_input("Enter an adjective ")

adjective2 = raw_input("Enter an adjective ")

animal = raw_input("Enter an animal ")

food = raw_input("Enter a food ")

verb = raw_input("Enter a verb ")

noun = raw_input("Enter a noun ")

fruit = raw_input("Enter a fruit ")

adjective3 = raw_input("Enter an adjective ")

name = raw_input("Enter a name ")

superhero = raw_input("Enter a superhero ")

name = raw_input("Enter a name ")

country = raw_input("Enter a country ")

name = raw_input("Enter a name ")

dessert = raw_input("Enter a dessert ")

name = raw_input("Enter a name ")

year = raw_input("Enter a year ")

noun2 = raw_input("Enter a noun ")

Hi @devrockstar94813,

Your final post does not include the original assignment to the STORY variable. There is also no print statement. Were they omitted from the post only, or did they accidentally get removed from your actual program?

From an earlier post:

After you complete the project, be sure to click any of the checkboxes that do not have checks in them.

I am sorry appylpye.
I only omitted the code from the last post.

Here is the full code (with the print statement at the end)
The issue I have now is that the story prints in the terminal but doesn’t apply the words I input, only shows %s

The template for the story

STORY = “This morning %s woke up feeling %s. ‘It is going to be a %s day!’ Outside, a bunch of %ss were protesting to keep %s in stores. They began to %s to the rhythm of the %s, which made all the %ss very %s. Concerned, %s texted %s, who flew %s to %s and dropped %s in a puddle of frozen %s. %s woke up in the year %s, in a world where %ss ruled the world.”

print “madlibs is starting”

name = raw_input("Enter a name ")
adjective1 = raw_input("Enter an adjective ")
adjective2 = raw_input("Enter an adjective ")
animal = raw_input("Enter an animal ")
food = raw_input("Enter a food ")
verb = raw_input("Enter a verb ")
noun1 = raw_input("Enter a noun ")
fruit = raw_input("Enter a fruit ")
adjective3 = raw_input("Enter an adjective ")
name = raw_input("Enter a name ")
superhero = raw_input("Enter a superhero ")
name = raw_input("Enter a name ")
country = raw_input("Enter a country ")
name = raw_input("Enter a name ")
dessert = raw_input("Enter a dessert ")
name = raw_input("Enter a name ")
year = raw_input("Enter a year ")
noun2 = raw_input("Enter a noun ")

print STORY

See instruction 11. In your final statement, you need to add the % operator followed by a tuple containing all the variables that correspond to the information specified in that instruction. Remember that based on that instruction, name needs to appear five times in the appropriate positions within that tuple. There needs to be a variable that corresponds to each occurrence of %s in STORY.