Change Contents of the Bubble
Welcome to CS1315. Click on the python to add comments.

Looking for the book? They have it at the Engineer's Bookstore at 748 Marietta St NW. Here is there website: http://www.engrbookstore.com/ - Monica

Hotspots: Slides and CodeTA CornerComments?AnnouncementsFAQStatic Webspace
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Final Exam Review Fall 2006: Handling an address book

Post your questions here:


def contact(wfind):
  addressbook=getMediaPath("addresses.txt")
  addresses=open(addressbook,"rt")
  addresstext=addresses.read()
  addresses.close()
  afound=addresstext.find(wfind)
  if afound==-1:
    print "Not Found"
  if afound!=-1:
    aend=addresstext.rfind(":",0,afound)
    astart=addresstext.rfind("#",0,afound)+1
    address=addresstext[astart:aend]
    print address


is this right? Jeffrey Geisert

This is what I get:
def contact (keyword):
  file=open(getMediaPath("contacts.txt"), "rt")
  address=file.read()
  file.close()
  lines = address.split ("\n")
  
  for i in lines:
    if i.find(keyword)!=-1:
      contactend=i.rfind(":")
      contactstart=i.rfind ("#")
      print i[contactstart+1:contactend]
    if i.find(keyword)==-1:
      print "not found" 


def contact(keyword):
file = file.open("contacts.txt","rt")
contacts = file.read()
file.close()
contacts.find(keyword)
if contacts !== -1:
begin = contacts.rfind("#", contacts)
end = contacts.rfind(":", contants)
print "contacts[begin:end]"
if contacts == -1:
print "Not Found"

would this work?

Not without indentions. -Brittany Duncan

def contact(keyword):
  file=getMediaPath("contacts.txt")
  file = open(file,"rt")
  contacts = file.read()
  file.close()
  k=contacts.find(keyword)
  if k != -1:
    begin = contacts.rfind("#",0,k)
    end = contacts.rfind(":",0,k)
    print contacts[begin+1:end]
  else:
    print "Not Found"

Jeffrey Wells



Link to this Page