[Tutor] getting keyboard input to dictionary (newbie ques)
alan.gauld@bt.com
alan.gauld@bt.com
Thu, 10 Jan 2002 12:29:05 -0000
> Def add_name():
> print "enter name"
As Danny has pointed out that needs to be 'def' not 'Def'.
Also you *must* indent the body lines:
def add_name():
print 'enter name'
# etc...
How much is up to you but usually 2 or 3 spaces or a single
tab are used. Just make sure its consistent.
> while 1:
> print "some greeting"
> print "type name to search"
> print "type 'add' to add names or 'quit' to exit"
> x=raw_input()
> if x=='quit':
> break
> d1={'a name':'1111', 'another name':'2222', 'A. Name':'1111'}
Danny said you *might* want to move this. I say you *definitely*
want to move this above the while...
> as if it is working ...
In that case your code must have the fubnction stuff
defined OK.
> ...but the entries are not added to the dict.
They probably are being assigned but when you go
round that while loop again... oops!
> I have tried converting the raw-input() value to a string
raw_input returns a string so no need for that.
> I'm missing something obvious... help.
Its easily done :-)
Alan g.