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

Midterm Exam 2 Review Spring 2006: Address book functions



i wrote this program for the first part of the wuestion only and i used only first line which is for Brown and i get "this is not a legal jethon...."

def lookUp(name):
 file = open(pickAFile(), "rt")
 file.read()
 text = file.readlines() 
 for list in text:
  splitlist = list.split(",")
  if splitlist[0].find(name) <>-1:
   print splitlist[4]
   return


i am sorry it isn't legal jethon message, it is "a local or global name coudn't be found".

is this correct for part b? 
def phone(string):
  file=open(address.txt, "rt")
  text=file.readlines()
  for entry in text:
    splitUpEntry = entry.split (":")
    if splitUpEntry[0].find(something) <> -1:
      print splitUpEntry [3]
    else:
      print "Not found"




something is wrong :) Colin Potts

I made the two functions, one to print the whole line, and one to print only the phone number. They both function perfectly fine until I try to include the "Not Found" part. If I put it in the "for" loop it prints "Not Found" several times (one for each line that the input string does not apply to) and the program will not run correctly if I place the "Not Found" command before or after the main code. Any suggestions/hints?
def lookup(twine):
  file = open(address.txt, "rt")
  for x in file.readlines():
    if x.find(twine) <>-1:
      print x

def phone(cord):
  file = open(address.txt, "rt")
  q = file.readlines()
  for x in q:
      if x.find(cord) <>-1:
        splitup = x.split(":")
        print splitup[3]




Link to this Page