-6
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 %s, your quest is %s, " \
"and your favorite color is $s." % (name, quest, color)

这是说在最后一行的字符串格式化期间并非所有参数都转换了

4

3 回答 3

7

你有一个错字。$s应该是%s为了使字符串格式化发生。因此,您尝试将三个参数填充到两个参数中。因此错误。

或者,您可以在str.format()这里使用:

print "Ah, so your name is {}, your quest is {}, and your favorite color is {}.".format(name, quest, color)
于 2013-10-28T10:20:53.470 回答
4

尝试改变

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

$s%s_color is

于 2013-10-28T10:21:49.710 回答
3

你有一个错字: $s而不是%s你的格式字符串

于 2013-10-28T10:21:03.547 回答