[Tutor] How do I call a variable within an input () function?

DaveA davea at davea.name
Fri Feb 6 08:29:50 CET 2015



On February 5, 2015 6:57:06 PM EST, Edgar Figueroa <figgypops at hotmail.com> wrote:
>Hello group.  I'm trying to call the variable "name" within my input ()

You're not needing to call it,  but to use it. The simplest answer is just to print the prompt separately,  and just call input  ().

Next option is to build a string in another variable,  like prompt= and then do input (prompt)

But there's no reason you can't just pass a single string expression directly to input.  Something like

X = input (name + ", what's your favorite food? ")

Now input gets exactly one argument. 

>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 () function.  Basically, I want the output to read as
>follows:
>Hello. What's your name?
>user enters "Frank"
>Hello Frank. Nice to meet you.
>Frank, what's your favorite food?
>Any help would be greatly appreciated. 
>Thanks. 		 	   		  
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.


More information about the Tutor mailing list