Stuck onstrings $ console output(string formatting with % part 2)


#1

Continuing the discussion from Strings & console output:

i have error while doing this
print "Ah, so your name is %s__, your quest is __%s, " \
"and your favorite color is %s__." __% (name, quest, color)


#2

Do not use underscores when using string formatting like that.

Example:String format like so.

response = {1: "Ah, so your name is %s, your quest is %s, and your favorite color is %s."}
print(response[1] % (name, color, quest))

#3

@sabin342

In this exercise you only have to "fill the blanks".
In this code:

name = raw_input("What is your name?")
quest = raw_input("What is your quest?")
color = raw_input("What is your favorite color?")

print "Ah, so your name is ___, your quest is ___, " \
"and your favorite color is ___." ___ (name, quest, color)

Replace the ___ with %s, and the last one with % (Just overwrite the ___)
What you're doing is using the %s character to tell to python that you want to place a string in that position.