Is it a newer version of Python that's the problem?


#1

Is it a newer version of python that is the problem? This code DOES NOT work for me and I copy/pasted it verbatim

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)

The error - Syntax Error - invalid syntax and it is pointing at the " in line 5


"String Formatting With %, Part 2"
#2

Did you try removing the quotes around the continuation character \...

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

#3

How would we type this in PyCharm, because the original format is not working? I'm using python 3.5.2


#4

Using the old string formatting approach...

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

Using the Python 3.x format() function...

s = "Ah, so your name is {0}, your quest is {1}, \
and your favorite color is {2}.".format(name, quest, color)
print (s)