错误“在字符串格式化期间未转换所有参数”

时间:2013-10-28 10:19:33

标签: python

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)

它说不是在最后一行的字符串格式化期间转换的所有参数

3 个答案:

答案 0 :(得分:7)

你有一个错字。 $s应为%s,以便进行字符串格式设置。因此,您有三个参数,您尝试填充两个参数。因此错误。

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

print "Ah, so your name is {}, your quest is {}, and your favorite color is {}.".format(name, quest, color)

答案 1 :(得分: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

答案 2 :(得分:3)

您的格式化字符串

中有一个拼写错误:$s而不是%s