[Tutor] Still stuck - but a bit further on.
Lisi
lisi.reisz at gmail.com
Sun Aug 28 15:53:25 CEST 2011
Sorry, everybody. I am still having problems with this script - tho' it now
runs correctly nearly to the end!
Here is the whole script:
#! /usr/bin/python
# create an empty address book dictionary
AddressBook = {}
# read entries till an empty string
print
name = raw_input("Type the Name - leave blank to finish")
while name != "":
entry = raw_input("Type the Street, Town, Phone. Leave blank to finish")
AddressBook[name] = entry
name = raw_input("Type the Name - leave blank to finish")
# now ask for one to display
name = raw_input("Which name to display?(blank to finish)")
while name !="":
print name, AddressBook[name]
name = raw_input("Which name to display?(blank to finish)")
I started with:
lisi at Tux:/usr/local/bin$ AddressBook
Type the Name - leave blank to finishLisi
Type the Street, Town, Phone. Leave blank to finishth, rc, 123457
Type the Name - leave blank to finish
Which name to display?(blank to finish) Lisi
Lisi
Traceback (most recent call last):
File "/usr/local/bin/AddressBook", line 17, in <module>
print name, AddressBook[name]
KeyError: ' Lisi'
I have tried various other words besides Lisi, each one less probable than its
predecessor. I am getting nowhere. The error may well be somewhere else
again, but I can't see where. :-(
Lisi
More information about the Tutor
mailing list