[Tutor] objects becoming pointers
Alan Gauld
alan.gauld at btinternet.com
Thu Jul 16 20:25:51 CEST 2009
"chris Hynes" <cjhynes36 at hotmail.com> wrote
> I want the user to input a name, say "Chris". I know I can use the code:
>
> name=raw_input()
>
> I now want:
>
> "Chris"=zeros((3,3))
>
> so that when I type:
>
> print Chris
This is a common misapprehension by beginners.
But let me ask you something. Since you will be writing your
program code, including the
print Chris
line, how will you know in advance what names your userrs are
going to input?
I think you will find it easier to create a dictiobnary of user names
with their associated values:
name = raw_input()
names[name] = value
name = raw_input("Which name was it?")
print names[name]
or even:
for name in names:
print names[name]
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list