[Tutor] How do I call a variable within an input () function?
Alan Gauld
alan.gauld at btinternet.com
Fri Feb 6 08:21:33 CET 2015
On 05/02/15 23:57, Edgar Figueroa wrote:
> 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.
You need to construct a single string argument.
There are several options:
"\n" + name + ", what's your favorite food? "
Or, better IMHO, use string formatting:
"\n {}, what's your favorite food? ".format(name)
formatting has the advantage of allowing you to insert multiple values
of different types and control spacing, justification and other aspects
of appearance.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list