Madlibs program throws ValueError
I'm learning Python through Codeacademy, and I'm having trouble with their Madlibs exercise. I've viewed the walkthrough after I began having trouble, but I can't see any differences between their code and mode. This is my code:
STORY = "This morning % woke up feeling %. 'It is going to be a % day!' Outside, a bunch of %s were protesting to keep % in stores. They began to % to the rhythm of the %, which made all the %s very %. Concerned, % texted %, who flew % to % and dropped % in a puddle of frozen %. % woke up in the year %, in a world where %s ruled the world."
print "Let the Madlibs begin!"
name = raw_input("Enter a name: ")
print "Please provide three adjectives: "
adj_1 = raw_input("1: ")
adj_2 = raw_input("2: ")
adj_3 = raw_input("3: ")
verb = raw_input("Enter a verb: ")
print "Now, input two nouns:"
noun_1 = raw_input("1: ")
noun_2 = raw_input("2: ")
print "Please provide a word for:"
animal = raw_input("An animal: ")
food = raw_input("A food: ")
fruit = raw_input("A fruit: ")
superhero = raw_input("A superhero: ")
country = raw_input("A country: ")
dessert = raw_input("A dessert: ")
year = raw_input("A year: ")
print STORY % (name, adj_1, adj_2, animal, food, verb, noun_1, noun_2, adj_3, name, superhero, name, country, name, dessert, name, year, noun_2)
When I run the program, I get the following error:
Traceback (most recent call last): File "Madlibs.py", line 34, in
print STORY % (name, adj_1, adj_2, animal, food, v erb, noun_1, noun_2, adj_3, name, superhero, name, cou ntry, name, dessert, name,
year, noun_2) ValueError: unsupported format character 'w' (0x77) at
index 15
Please help me see what I'm missing. Thank you!
python-2.7
add a comment |
I'm learning Python through Codeacademy, and I'm having trouble with their Madlibs exercise. I've viewed the walkthrough after I began having trouble, but I can't see any differences between their code and mode. This is my code:
STORY = "This morning % woke up feeling %. 'It is going to be a % day!' Outside, a bunch of %s were protesting to keep % in stores. They began to % to the rhythm of the %, which made all the %s very %. Concerned, % texted %, who flew % to % and dropped % in a puddle of frozen %. % woke up in the year %, in a world where %s ruled the world."
print "Let the Madlibs begin!"
name = raw_input("Enter a name: ")
print "Please provide three adjectives: "
adj_1 = raw_input("1: ")
adj_2 = raw_input("2: ")
adj_3 = raw_input("3: ")
verb = raw_input("Enter a verb: ")
print "Now, input two nouns:"
noun_1 = raw_input("1: ")
noun_2 = raw_input("2: ")
print "Please provide a word for:"
animal = raw_input("An animal: ")
food = raw_input("A food: ")
fruit = raw_input("A fruit: ")
superhero = raw_input("A superhero: ")
country = raw_input("A country: ")
dessert = raw_input("A dessert: ")
year = raw_input("A year: ")
print STORY % (name, adj_1, adj_2, animal, food, verb, noun_1, noun_2, adj_3, name, superhero, name, country, name, dessert, name, year, noun_2)
When I run the program, I get the following error:
Traceback (most recent call last): File "Madlibs.py", line 34, in
print STORY % (name, adj_1, adj_2, animal, food, v erb, noun_1, noun_2, adj_3, name, superhero, name, cou ntry, name, dessert, name,
year, noun_2) ValueError: unsupported format character 'w' (0x77) at
index 15
Please help me see what I'm missing. Thank you!
python-2.7
add a comment |
I'm learning Python through Codeacademy, and I'm having trouble with their Madlibs exercise. I've viewed the walkthrough after I began having trouble, but I can't see any differences between their code and mode. This is my code:
STORY = "This morning % woke up feeling %. 'It is going to be a % day!' Outside, a bunch of %s were protesting to keep % in stores. They began to % to the rhythm of the %, which made all the %s very %. Concerned, % texted %, who flew % to % and dropped % in a puddle of frozen %. % woke up in the year %, in a world where %s ruled the world."
print "Let the Madlibs begin!"
name = raw_input("Enter a name: ")
print "Please provide three adjectives: "
adj_1 = raw_input("1: ")
adj_2 = raw_input("2: ")
adj_3 = raw_input("3: ")
verb = raw_input("Enter a verb: ")
print "Now, input two nouns:"
noun_1 = raw_input("1: ")
noun_2 = raw_input("2: ")
print "Please provide a word for:"
animal = raw_input("An animal: ")
food = raw_input("A food: ")
fruit = raw_input("A fruit: ")
superhero = raw_input("A superhero: ")
country = raw_input("A country: ")
dessert = raw_input("A dessert: ")
year = raw_input("A year: ")
print STORY % (name, adj_1, adj_2, animal, food, verb, noun_1, noun_2, adj_3, name, superhero, name, country, name, dessert, name, year, noun_2)
When I run the program, I get the following error:
Traceback (most recent call last): File "Madlibs.py", line 34, in
print STORY % (name, adj_1, adj_2, animal, food, v erb, noun_1, noun_2, adj_3, name, superhero, name, cou ntry, name, dessert, name,
year, noun_2) ValueError: unsupported format character 'w' (0x77) at
index 15
Please help me see what I'm missing. Thank you!
python-2.7
I'm learning Python through Codeacademy, and I'm having trouble with their Madlibs exercise. I've viewed the walkthrough after I began having trouble, but I can't see any differences between their code and mode. This is my code:
STORY = "This morning % woke up feeling %. 'It is going to be a % day!' Outside, a bunch of %s were protesting to keep % in stores. They began to % to the rhythm of the %, which made all the %s very %. Concerned, % texted %, who flew % to % and dropped % in a puddle of frozen %. % woke up in the year %, in a world where %s ruled the world."
print "Let the Madlibs begin!"
name = raw_input("Enter a name: ")
print "Please provide three adjectives: "
adj_1 = raw_input("1: ")
adj_2 = raw_input("2: ")
adj_3 = raw_input("3: ")
verb = raw_input("Enter a verb: ")
print "Now, input two nouns:"
noun_1 = raw_input("1: ")
noun_2 = raw_input("2: ")
print "Please provide a word for:"
animal = raw_input("An animal: ")
food = raw_input("A food: ")
fruit = raw_input("A fruit: ")
superhero = raw_input("A superhero: ")
country = raw_input("A country: ")
dessert = raw_input("A dessert: ")
year = raw_input("A year: ")
print STORY % (name, adj_1, adj_2, animal, food, verb, noun_1, noun_2, adj_3, name, superhero, name, country, name, dessert, name, year, noun_2)
When I run the program, I get the following error:
Traceback (most recent call last): File "Madlibs.py", line 34, in
print STORY % (name, adj_1, adj_2, animal, food, v erb, noun_1, noun_2, adj_3, name, superhero, name, cou ntry, name, dessert, name,
year, noun_2) ValueError: unsupported format character 'w' (0x77) at
index 15
Please help me see what I'm missing. Thank you!
python-2.7
python-2.7
asked Nov 15 '18 at 0:57
Mitch MillerMitch Miller
71
71
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Your format string (STORY
) has some invalid placeholders in it. When you're formatting a string, you have to specify what type of data will be put at each placeholder. You do this by putting a letter after the %
sign. In this case, since you're always putting in a string, that should be an s
. So, STORY
should start like this:
STORY = "This morning %s woke up feeling %s. [...]"
There are more details about this syntax in the Python documentation, which explains how to do things like format numbers in a certain way.
(However, it's worth bearing in mind that in modern Python we normally use a newer syntax using str.format()
, which looks like this:
STORY = "This morning name woke up feeling adj_1. [...]"
print STORY.format(name="James", adj_1="terrible")
)
That was it! Thanks. Can't believe I forgot the s's. Cheers!
– Mitch Miller
Nov 15 '18 at 2:33
Great! Please accept the answer by clicking the check mark next to it. That way the question will be marked resolved.
– Harry Cutts
Nov 15 '18 at 18:16
All done. Thanks again!
– Mitch Miller
Nov 16 '18 at 20:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310978%2fmadlibs-program-throws-valueerror%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your format string (STORY
) has some invalid placeholders in it. When you're formatting a string, you have to specify what type of data will be put at each placeholder. You do this by putting a letter after the %
sign. In this case, since you're always putting in a string, that should be an s
. So, STORY
should start like this:
STORY = "This morning %s woke up feeling %s. [...]"
There are more details about this syntax in the Python documentation, which explains how to do things like format numbers in a certain way.
(However, it's worth bearing in mind that in modern Python we normally use a newer syntax using str.format()
, which looks like this:
STORY = "This morning name woke up feeling adj_1. [...]"
print STORY.format(name="James", adj_1="terrible")
)
That was it! Thanks. Can't believe I forgot the s's. Cheers!
– Mitch Miller
Nov 15 '18 at 2:33
Great! Please accept the answer by clicking the check mark next to it. That way the question will be marked resolved.
– Harry Cutts
Nov 15 '18 at 18:16
All done. Thanks again!
– Mitch Miller
Nov 16 '18 at 20:00
add a comment |
Your format string (STORY
) has some invalid placeholders in it. When you're formatting a string, you have to specify what type of data will be put at each placeholder. You do this by putting a letter after the %
sign. In this case, since you're always putting in a string, that should be an s
. So, STORY
should start like this:
STORY = "This morning %s woke up feeling %s. [...]"
There are more details about this syntax in the Python documentation, which explains how to do things like format numbers in a certain way.
(However, it's worth bearing in mind that in modern Python we normally use a newer syntax using str.format()
, which looks like this:
STORY = "This morning name woke up feeling adj_1. [...]"
print STORY.format(name="James", adj_1="terrible")
)
That was it! Thanks. Can't believe I forgot the s's. Cheers!
– Mitch Miller
Nov 15 '18 at 2:33
Great! Please accept the answer by clicking the check mark next to it. That way the question will be marked resolved.
– Harry Cutts
Nov 15 '18 at 18:16
All done. Thanks again!
– Mitch Miller
Nov 16 '18 at 20:00
add a comment |
Your format string (STORY
) has some invalid placeholders in it. When you're formatting a string, you have to specify what type of data will be put at each placeholder. You do this by putting a letter after the %
sign. In this case, since you're always putting in a string, that should be an s
. So, STORY
should start like this:
STORY = "This morning %s woke up feeling %s. [...]"
There are more details about this syntax in the Python documentation, which explains how to do things like format numbers in a certain way.
(However, it's worth bearing in mind that in modern Python we normally use a newer syntax using str.format()
, which looks like this:
STORY = "This morning name woke up feeling adj_1. [...]"
print STORY.format(name="James", adj_1="terrible")
)
Your format string (STORY
) has some invalid placeholders in it. When you're formatting a string, you have to specify what type of data will be put at each placeholder. You do this by putting a letter after the %
sign. In this case, since you're always putting in a string, that should be an s
. So, STORY
should start like this:
STORY = "This morning %s woke up feeling %s. [...]"
There are more details about this syntax in the Python documentation, which explains how to do things like format numbers in a certain way.
(However, it's worth bearing in mind that in modern Python we normally use a newer syntax using str.format()
, which looks like this:
STORY = "This morning name woke up feeling adj_1. [...]"
print STORY.format(name="James", adj_1="terrible")
)
edited Nov 15 '18 at 1:45
answered Nov 15 '18 at 1:38
Harry CuttsHarry Cutts
1,060921
1,060921
That was it! Thanks. Can't believe I forgot the s's. Cheers!
– Mitch Miller
Nov 15 '18 at 2:33
Great! Please accept the answer by clicking the check mark next to it. That way the question will be marked resolved.
– Harry Cutts
Nov 15 '18 at 18:16
All done. Thanks again!
– Mitch Miller
Nov 16 '18 at 20:00
add a comment |
That was it! Thanks. Can't believe I forgot the s's. Cheers!
– Mitch Miller
Nov 15 '18 at 2:33
Great! Please accept the answer by clicking the check mark next to it. That way the question will be marked resolved.
– Harry Cutts
Nov 15 '18 at 18:16
All done. Thanks again!
– Mitch Miller
Nov 16 '18 at 20:00
That was it! Thanks. Can't believe I forgot the s's. Cheers!
– Mitch Miller
Nov 15 '18 at 2:33
That was it! Thanks. Can't believe I forgot the s's. Cheers!
– Mitch Miller
Nov 15 '18 at 2:33
Great! Please accept the answer by clicking the check mark next to it. That way the question will be marked resolved.
– Harry Cutts
Nov 15 '18 at 18:16
Great! Please accept the answer by clicking the check mark next to it. That way the question will be marked resolved.
– Harry Cutts
Nov 15 '18 at 18:16
All done. Thanks again!
– Mitch Miller
Nov 16 '18 at 20:00
All done. Thanks again!
– Mitch Miller
Nov 16 '18 at 20:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53310978%2fmadlibs-program-throws-valueerror%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown