String Formatting with %, Part 2?


#1

Hello everyone, I am stuck with this excercise. Can anyone help me??
BEFORE:
print "Ah, so your name is ___, your quest is ___, " \
"and your favorite color is ___." ___ (name, quest, color)

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

Everything it is in its place, but it sends me this message:
Traceback (most recent call last):
File "python", line 6, in
NameError: name 'Jack' is not defined

Hope someone helps me :smile:


#2

Create a variable called jack, or make it into a string.


#3

Im a noobies so I have no idea what do you mean. Can you please explain??


#4

(Jack, uni, blue) In this line you are referring to the variables Jack, uni and blue. But they dont seem to be in your code. You can define them by putting Jack = "Jack" in the start of your code for example.


#5

name = raw_input("What is your name?")
quest = raw_input("What is your quest?")
color = raw_input("What is your favorite color?")

I remove raw_input and put jack and on quest uni and on color blue. Still doesn't work


#6

raw_input() is the call for the function that allows the user to type something in so that needs to be there. The name of your variables are name, quest and color. So try putting those in the parenthesis instead of Jack, uni and blue.


#7

Halleluja, thanks a lot I used to put jack, uni and blue instead of just typing name quest and color! Got it! :smile:


#8

This should better illustrate my "Python" program language problem. My syntax states, print "Ah, so your name is %s__, your quest is _%s__, " \ "and your favorite color is _%s__." %. However, the code keeps running.

Sincerely,

Ian Michael Jones


#9

There =]

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)

Don't forget to add the "%" before "(name, quest, color)"


#10

My code syntax was the same as yours and I did exactly what you requested and ran the code, but it says, "Not enough arguments in the s string." Please advise.


#11

Hmm that's weird, have you added the ''\'' in between

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


#12

After many attempts!
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)
Code should be clean, delete all unnecessary.


#13