String Formatting with %, Part 2 issues... Help!


#1
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." %s (name, quest, color)

What is wrong with this code? I always get the "Traceback (most recent call last): File "python", line 6, in NameError: name 's' is not defined" error ???


#2

%s in a string doesn't try to find a variable by that name, but you're using s somewhere else as well.


#3

%s (name, quest, color)
The issue is in your %s in the line above you should use % only


#4

I'm sorry but Im still very new to coding. I dont understand Python to well, can you please explain better?


#5

Your mistake was using adding a "s" at the end of %.
Correct % (name, quest, color)
Incorrect %s (name, quest, color)

Unless what you're trying to ask is, what's the difference between the string method "%s" and "%"?


#6

thanks mate. that's great help. :slight_smile: