Madlibs madness


#1

LEARN PYTHON 2

Python Mad Libs

Tried the following many times but got this error: type error, not all arguments converted during string formatting. What is wrong? Thanks.

STORY = “This morning %s woke up feeling %s. ‘It is going to be a %s day!’ Outside, a bunch of %s were protesting to keep %s in stores. They began to %s to the rhythm of the %s, which made all the %s 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 %s ruled the world.”

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


#2

Try replacing the STORY variable in the print statement with the content of the variable - take STORY out of the picture.


#3

This generally indicates more arguments than format strings.


#4

Thanks, mtf! But they both have 18?


#5

Thanks, triskaidekaphile. What did you mean by putting the actual variable in the print statement? THe actual user input?


#6

Like, eliminate STORY. I’ll edit the original so it doesn’t confuse anyone.


#7

That much I could check, but we cannot see your variable declarations, which is another possible spot for an error or omission to be found.

No, don’t do that. The SCT expects to see print Story....


#8

sorry, here they are:

print “Mad Libs has started”
name = raw_input("Enter a name: ")
adjective1 = raw_input('Enter an adjective: ')
adjective2 = raw_input('Enter a second adjective: ')
adjective3 = raw_input('Enter one more adjective: ')
verb = raw_input('Enter a verb: ')
noun1 = raw_input('Enter a noun: ')
noun2 = raw_input('Enter a scond 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: ')


#9

I’ve run your code and did not reproduce the error.

>>> name = input("Enter a name: ");adjective1 = input('Enter an adjective: ');adjective2 = input('Enter a second adjective: ');adjective3 = input('Enter one more adjective: ');verb = input('Enter a verb: ');noun1 = input('Enter a noun: ');noun2 = input('Enter a scond noun: ');animal = input('Enter an animal: ');food = input('Enter a food: ');fruit = input('Enter a fruit: ');superhero = input('Enter a superhero: ');country = input('Enter a country: ');dessert = input('Enter a dessert: ');year = input('Enter a year: ');
Enter a name: 1
Enter an adjective: 2
Enter a second adjective: 3
Enter one more adjective: 4
Enter a verb: 5
Enter a noun: 6
Enter a scond noun: 7
Enter an animal: 8
Enter a food: 9
Enter a fruit: 10
Enter a superhero: 11
Enter a country: 12
Enter a dessert: 13
Enter a year: 14
>>> STORY = "This morning %s woke up feeling %s. ‘It is going to be a %s day!’ Outside, a bunch of %s were protesting to keep %s in stores. They began to %s to the rhythm of the %s, which made all the %s 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 %s ruled the world."
>>> print (STORY % (name, adjective1, adjective2, animal, food, verb, noun1, fruit, adjective3, name, superhero, name, country, name, dessert, name, year, noun2))
This morning 1 woke up feeling 2. ‘It is going to be a 3 day!’ Outside, a bunch of 8 were protesting to keep 9 in stores. They began to 5 to the rhythm of the 6, which made all the 10 very 4. Concerned, 1 texted 11, who flew 1 to 12 and dropped 1 in a puddle of frozen 13. 1 woke up in the year 14, in a world where 7 ruled the world.
>>> 

#10

Thank you, mtf! I ran it again using numbers like you did and it worked. Don’t know why it didn’t work before when I used actual words.


#11

However, it’s not letting me proceed to the next exercise. Maybe they want actual words?


#12
>>> name = input("Enter a name: ");adjective1 = input('Enter an adjective: ');adjective2 = input('Enter a second adjective: ');adjective3 = input('Enter one more adjective: ');verb = input('Enter a verb: ');noun1 = input('Enter a noun: ');noun2 = input('Enter a scond noun: ');animal = input('Enter an animal: ');food = input('Enter a food: ');fruit = input('Enter a fruit: ');superhero = input('Enter a superhero: ');country = input('Enter a country: ');dessert = input('Enter a dessert: ');year = input('Enter a year: ');
Enter a name: a
Enter an adjective: b
Enter a second adjective: c
Enter one more adjective: d
Enter a verb: e
Enter a noun: f
Enter a scond noun: g
Enter an animal: h
Enter a food: i
Enter a fruit: j
Enter a superhero: k
Enter a country: l
Enter a dessert: m
Enter a year: n
>>> print (STORY % (name, adjective1, adjective2, animal, food, verb, noun1, fruit, adjective3, name, superhero, name, country, name, dessert, name, year, noun2))
This morning a woke up feeling b. ‘It is going to be a c day!’ Outside, a bunch of h were protesting to keep i in stores. They began to e to the rhythm of the f, which made all the j very d. Concerned, a texted k, who flew a to l and dropped a in a puddle of frozen m. a woke up in the year n, in a world where g ruled the world.
>>> 

Again, no errors. Recall that even while we used numbers, they were actually strings, since they came from raw_input (or input in my case, Python 3).


#13

This is weird. I used real words and they worked but it still won’t let me proceed to the next section.


#14

Are you supposed to check off the steps? If so, remember to check off the video if it is present.

Oh, and if it is a free form project, there is no SCT. Anything goes.


#15

You’re right! I missed a couple of checks and now I can proceed. Thank you so much!