Python Madlibs.py code and error message
Cai Gengyang
gengyangcai at gmail.com
Thu Apr 28 01:01:21 EDT 2016
I changed it to all lowercase, this time I get a different error message though (a TypeError message)
# This program does the following ... writes a Mad Libs story
# Author: Cai Gengyang
print "Mad Libs is starting!"
name = raw_input("Enter a name: ")
adjective1 = raw_input("Enter an adjective: ")
adjective2 = raw_input("Enter a second adjective: ")
adjective3 = raw_input("Enter a third adjective: ")
verb1 = raw_input("Enter a verb: ")
verb2 = raw_input("Enter a second verb: ")
verb3 = raw_input("Enter a third verb: ")
noun1 = raw_input("Enter a noun: ")
noun2 = raw_input("Enter a noun: ")
noun3 = raw_input("Enter a noun: ")
noun4 = raw_input("Enter a 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: ")
superhero_name = raw_input("Enter a superhero_name: ")
country = raw_input("Enter a country: ")
dessert = raw_input("Enter a dessert: ")
year = raw_input("Enter a year: ")
#The template for the story
STORY = "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."
print STORY % (adjective1, name, verb1, adjective2, noun1, noun2, animal, food, verb2, noun3, fruit, adjective3, name, verb3, number, name , superhero_name, superhero_name, name, country, name, dessert, name, year, noun4)
Terminal Output :
$ python Madlibs.py
Mad Libs is starting!
Enter a name: andrew
Enter an adjective: beautiful
Enter a second adjective: honest
Enter a third adjective: pretty
Enter a verb: hit
Enter a second verb: run
Enter a third verb: fire
Enter a noun: honesty
Enter a noun: love
Enter a noun: peace
Enter a noun: wisdom
Enter an animal: elephant
Enter a food: burger
Enter a fruit: watermelon
Enter a number: 1985
Enter a superhero_name: batman
Enter a country: america
Enter a dessert: icekachang
Enter a year: 1982
Traceback (most recent call last):
File "Madlibs.py", line 34, in <mo
dule>
print STORY % (adjective1, name,
verb1, adjective2, noun1, noun2, an
imal, food, verb2, noun3, fruit, adj
ective3, name, verb3, number, name ,
superhero_name, superhero_name, nam
e, country, name, dessert, name, yea
r, noun4)
TypeError: not all arguments converted during string formatting
On Thursday, April 28, 2016 at 12:50:28 PM UTC+8, Gregory Ewing wrote:
> Cai Gengyang wrote:
>
> > adjective1 = raw_input("Enter an adjective: ")
> >
> > NameError: name 'Adjective1' is not defined
>
> Python is case-sensitive. You've spelled it "adjective1" in one
> place and "Adjective1" in another. You need to be consistent.
>
> --
> Greg
More information about the Python-list
mailing list