On 06/02/2015 07:20, Danny Yoo wrote:
On Thu, Feb 5, 2015 at 3:57 PM, Edgar Figueroa <figgyp...@hotmail.com> wrote:
Hello group.  I'm trying to call the variable "name" within my input () 
function.
Here's what I have:
name = input("Hello. What's your name? ")
print("\nHello", name, ". Nice to meet you.")
favFood1 = input("\n", name, ", what's your favorite food? ")
Obviously it isn't working.  It tells me I have too many arguments for the 
input ()

Try not to paraphrase error messages.  Rather, copy-and-paste the
error message exactly as the computer says.  This might seem counter
to what you're used to doing, but it helps because sometimes the
slightest detail helps to figure out what's going on.

In particular, your program has *two* uses of input.  But the error
message should have said which one was problematic, and I'm pretty
sure it has done so!  But since you've paraphrased the message, we
would not be able to tell which one was broken, even if the error
message said exactly which one was wrong.  *That's* why you should
avoid paraphrasing error messages.

In any case, since there's only two, we can look and see that the
problematic one is probably this:

     favFood1 = input("\n", name, ", what's your favorite food? ")

You want to pass input() a single string.  But you have a few strings there.

Do you know about "string appending" or "string concatenation"?


String formatting should also be mentioned, old style using the % operator as in C or new style using {} and format.

favFood1 = input("\n%s what's your favorite food? " % name)
favFood1 = input("\n{} what's your favorite food? ".format(name))

I much prefer the latter as I find it far more flexible.

--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to