Madlibs help

I’m currently working on the Madlibs section in Python 2 and stuck on the final step.

I run the code and I end up with an error.

Traceback (most recent call last):
  File "Madlibs.py", line 31, in <module>
    print STORY % (name, adj1, adj2, ani1, food1, verb1, noun1
, fruit1, adj3, name, superh1, name, coun1, name, dess1, name,
 year1, noun1)
TypeError: %d format: a number is required, not str

I’ve tried googling and I just don’t feel like I know enough to be able to figure out exactly what my problem is.

Thank you for any advice and help in advance.

"""
This program generates passages that are generated in mad-lib format
Author: Katherin 
"""

# 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 %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 'Mad Libs has started!'

name = raw_input('Enter a name: ')

adj1 = raw_input('Enter 1/3 adjective: ')
adj2 = raw_input('Enter 2/3 adjective: ')
adj3 = raw_input('Enter 3/3 adjective: ')

verb1 = raw_input('Enter a verb: ')

noun1 = raw_input('Enter a noun: ')
noun2 = raw_input('Enter a second noun: ')

ani1 = raw_input('Enter your favourite animal: ')
food1 = raw_input('Enter your favourite food: ')
fruit1 = raw_input('Enter your favourite fruit: ')
superh1 = raw_input('Enter your favourite superhero: ')
coun1 = raw_input('Enter your favourite country: ')
dess1 = raw_input('Enter your favourite dessert: ')
year1 = raw_input('Enter a random year: ')

print STORY % (name, adj1, adj2, ani1, food1, verb1, noun1, fruit1, adj3, name, superh1, name, coun1, name, dess1, name, year1, noun1)

Hello, @adamragg, and welcome to the forums.

The code you posted, does not throw the error you’ve referenced.

Embarrassing, I’ve run it a through times through the Codecademy and it seems to each time. If I’m not actually doing anything wrong though, might be an error in the training environment.

Thanks anyway!

The only way this error can crop up is when that directive is applied. It’s nowhere to be found in your code. The more important question, before moving on from this lesson is, do you understand the directives given in the modulo syntax? If not, then don’t leave this unit until you do. There are online aids to this process. Don’t be afraid to consult them, just don’t leave this unit until you have a good understanding of it.

I thought I did, my first instinct upon reading the TypeError was to retrace my code and find if I had somehow placed a %d instead. I retraced and retraced to find no particular error. But each time I replaced my code, and rechecked, I never found the issue but it still reports the TypeError.

That is very weird. It won’t affect your progress if you just skip along. What’s more, this is more for poking around in the old Python than anything else. Take what you can from this track but get into Python 3 as quick as you can and forget this old, outdated stuff.

2 Likes