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)
它说不是在最后一行的字符串格式化期间转换的所有参数
答案 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