This code is for Code Academy's Madlibs exercise, which is supposed to take a number of inputs from the user and then print a very funny output.
There is a story already provided in the site and I have not modified it.
When I run the script, I am getting the following error:
Traceback (most recent call l ast):
File "Madlibs.py", line 30, in
print "This morning I woke up and felt %s because _ was going to finally %s over the big _ %s. On the other side of the %s were many %ss protesting to keep %s in stores. The crowd began to _ to the rythym of the %s, which made all of the %ss very _. %s tried to _ into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping _ into a puddle of %s. %s then fell asleep and woke up in the year _, in a world where %ss ruled the world." %(a1, name, v1, a2,n1, n2, Animal, Food, v2, n3,Fruit, a3, name, v3, Number,name, Superhero, Superhero, name, Country, name, Dessert,name, Year, n4)TypeError: not all arguments converted during string formatting
The output also prints the "print" !!!
Please note that in the story, there are some places where we have '%ss' instead of '%s'. Codeacademy wants the users to use '%ss' (I believe so)
Also, I tried replacing the '%ss' with '%s' - I got the same error.
Replaced all the '%s' and '%ss' with '%r' and '%rr' and got the same error.
Replaced '%rr' with '%r' throughout and got the same error.
One more thing I must mention, the code asks the user for all of the raw_input correctly, but fails to replace those in the story and prints the story with just %s or %r along with the error message.
Can someone kindly help me out here. My code seems fine to me and I don't understand what's going on with the error message.
Following is the code (Please bear with me for this repetitive piece)
# This is a story for Mad Libs !!!
print "Mad Lib is staritng now."
name = raw_input ("What's your name ?")
a1 = raw_input ("How are you feeling today ?")
a2 = raw_input ("How is ther weather?")
a3 = raw_input("Would you like your coffee hot or cold?")
v1 = raw_input ("Would you rather jump, run or walk ?")
v2 = raw_input ("Would you rather sing, dance or act ?")
v3 = raw_input ("Would you rather eat, sleep or watch ?")
n1 = raw_input ("In which city do you live ?")
n2 = raw_input ("What is your favourite pet ?")
n3 = raw_input ("Would you like to go to a mountain or a beach ?")
n4 = raw_input ("DO you wnat to buy a dress or a shoe? ")
Animal = raw_input ("Which animal do you like the most ?")
Food = raw_input ("Enter your favourite food")
Fruit = raw_input ("What's your favourite fruit ?")
Number = raw_input ("Tell me a number: ")
Superhero = raw_input ("Tell me the name of one Superhero")
Country = raw_input ("Which country would you like to visit on your next vacation ?")
Dessert = raw_input ("Which is your favourite dessert ?")
Year = raw_input ("Which year were you born ?")
print "This morning I woke up and felt %s because _ was going to finally %s over the big _ %s. On the other side of the %s were many %ss protesting to keep %s in stores. The crowd began to _ to the rythym of the %s, which made all of the %ss very _. %s tried to _ into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping _ into a puddle of %s. %s then fell asleep and woke up in the year _, in a world where %ss ruled the world." %(a1, name, v1, a2, n1, n2, Animal, Food, v2, n3, Fruit, a3, name, v3, Number, name, Superhero, Superhero, name, Country, name, Dessert, name, Year, n4)
This link provides a solution. Read toward the bottom. It seems that you need to replace all the _ with %s.
So for example instead of
print "This morning I woke up and felt %s because _ was going to finally %s over the big _ %s. On the other side of the %s were many %ss protesting to keep %s in stores. The crowd began to _ to the rythym of the %s, which made all of the %ss very _. %s tried to _ into the sewers and found %s rats. Needing help, %s quickly called %s. %s appeared and saved %s by flying to %s and dropping _ into a puddle of %s. %s then fell asleep and woke up in the year _, in a world where %ss ruled the world." %(a1, name, v1, a2, n1, n2, Animal, Food, v2, n3, Fruit, a3, name, v3, Number, name, Superhero, Superhero, name, Country, name, Dessert, name, Year, n4)
It should be
print "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 %s protesting to keep %s in stores. The crowd began to %s to the rythym of the %s, which made all of the %s 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 %s ruled the world." %(a1, name, v1, a2, n1, n2, Animal, Food, v2, n3, Fruit, a3, name, v3, Number, name, Superhero, Superhero, name, Country, name, Dessert, name, Year, n4)