Caculate age

Laura Creighton lac at strakt.com
Mon Feb 3 00:22:26 CET 2003


> --0-1253328135-1044223072=:10654
> Content-Type: text/plain; charset=us-ascii
> 
> 
> Thanks for your quick response. 
> I am trying to write a function which will take a String as an argument and a
> dd it to a hashtable. If the value entered is in the Hashtable then print it 
> or else error out. 

This will go better if you paste in what you get out of the
Python interpreter.

> Here is what I have written so far : 
> import sys 
> def mydict(y):

def makes a function.  They are usually thought of like verbs.
So def make_a_dict(y):  might be the sort of thing that you are looking
for.  But I think that you simply want to in itialize your dictionary.

mydict={}  will do this for you.
> #y = raw_input ("Please enter a String: ")
>     if len(y) > 1:
>         x={}

Now you have make an empty dictionary.  I don't think you wanted to.

>         #x={i:y}
>         x[i] = i
>         x[i] = y
>         i = i+1

where did this i come from?  remember that strings make great
keys for your dictionary.  Numbers do not. 

>         #return x.values()
> #print x.has_key(1)
> #y=x.keys()
> #z=x.values()
> #print y, z
> print x.keys()
> print x.values()

Now you would like to go back to raw_input, wouldn't you?
But you aren't in a loop, so python is going to keep wanting
the next statement.  You need a way to tell it to go back to
the top.

> 
> Any advice ! 
> -Thanks

It is after midnight here in Sweden. I am going to bed.  Good luck,
post your code with the results from the interpreter, and more
specific questions.  If you can manage to not sent out messages
in HTML format, that would be great also.

Good luck,
Laura Creighton





More information about the Python-list mailing list