Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question Details Please include all proper indentions. You will be awarded 140 K

ID: 3619829 • Letter: Q

Question

Question Details
Please include all proper indentions.
You will be awarded 140 Karama Points!
Please copy and paste entire .py file

Someone else gave me some code to enhance this program
But I am not sure how to integrate it into the program
I pasted the code below the program at the bottom.
Thank You
-----
You've been going to work on a database project at work for sometime now. Your boss encourages you to program the database in Python. You disagree, arguing that Python is not a database language but your boss persists by providing the source code below for a sample telephone database. He asks you to do two things:

1. Evaluate the existing source code and extend it to make it useful for managers in the firm. (You do not need a GUI interface, just work on the database aspects: data entry and retrieval - of course you must get the program to run or properly work, and

2. He wants you to critically evaluate Python as a database tool.

Import the sample code below into the Python IDLE and enhance it, run it and debug it. Add features to make this a more realistic database tool by providing for easy data entry and retrieval. Export your successful program to a Python file for later upload to coursenet.

Here is the sample source code:

#!/usr/bin/python
#
# An example from Sean Reifschneider's Python Tutorial at Linux Expo 98.
#
# Copyright (c) 1998 Sean Reifschneider, tummy.com, ltd.
#
# Simple phone-number database module

import shelve
import string

UNKNOWN = 0
HOME = 1
WORK = 2
FAX = 3
CELL = 4

class phoneentry:
def __init__(self, name = 'Unknown', number = 'Unknown',
type = UNKNOWN):
self.name = name
self.number = number
self.type = type

# create string representation
def __repr__(self):
return('%s:%d' % ( self.name, self.type ))

# fuzzy compare or two items
def __cmp__(self, that):
this = string.lower(str(self))
that = string.lower(that)

if string.find(this, that) >= 0:
return(0)
return(cmp(this, that))

def showtype(self):
if self.type == UNKNOWN: return('Unknown')
if self.type == HOME: return('Home')
if self.type == WORK: return('Work')
if self.type == FAX: return('Fax')
if self.type == CELL: return('Cellular')

class phonedb:
def __init__(self, dbname = 'phonedata'):
self.dbname = dbname;
self.shelve = shelve.open(self.dbname);

def __del__(self):
self.shelve.close()
self.shelve = None

def add(self, name, number, type = HOME):
e = phoneentry(name, number, type)
self.shelve[str(e)] = e

def lookup(self, string):
list = []
for key in self.shelve.keys():
e = self.shelve[key]
if cmp(e, string) == 0:
list.append(e)

return(list)

# if not being loaded as a module, run a small test
if __name__ == '__main__':
foo = phonedb()
foo.add('Sean Reifschneider', '970-555-1111', HOME)
foo.add('Sean Reifschneider', '970-555-2222', CELL)
foo.add('Evelyn Mitchell', '970-555-1111', HOME)

print 'First lookup:'
for entry in foo.lookup('reifsch'):
print '%-40s %s (%s)' % ( entry.name, entry.number, entry.showtype() )
print

print 'Second lookup:'
for entry in foo.lookup('e'):
print '%-40s %s (%s)' % ( entry.name, entry.number, entry.showtype() )

------------------ADDON CODE-----------------------------

Someone else gave me some code to enhance this program
But I am not sure how to integrate it into the program
------
import sys
from phone import *

#Start of Program
b = 1
foo = phonedb()//list of phonedb
while b != 3:
print b
print "Welcome to the Phone Database!"
//Displaying menu
print "Please make a selection by typing one of the following options."
print "If you want to add an Employee type the #: 1"
print"For a complete listing of Employees type the #: 2"
print "To see the 'test page' and exit the Database type the #: 3"
b = input(':')//input choice
if b == 1:
//inputting employee name
print "Enter the Employee's full name:"
n = raw_input(':')
//inputting employee telephone number
print "Enter the Employee's full telephone number:"
p = raw_input(':')
//inputting employee telephone type
print "Enter the telephone number type: (0 = UNKNOWN, 1 = HOME, 2 = WORK, 3 = FAX, 4 = CELL)"
t = raw_input(':')
if t == '0':
foo.add(n, p, UNKNOWN)
if t == '1':
foo.add(n, p, "HOME")
if t == '2':
foo.add(n, p, "WORK")
if t == '3':
foo.add(n, p, "FAX")
if t == '4':
foo.add(n, p, "CELL")

print t

if b == 2:
print (list)

Explanation / Answer

import shelve import string class phoneentry: name = ""; number = 0; typeOfNum = 0; UNKNOWN = 0 HOME = 1 WORK = 2 FAX = 3 CELL = 4 def __init__(self, name,number,typeOfNum): self.name = name; self.number =number; self.typeOfNum = typeOfNum; class phonedb: dbname = "phoneDat.txt"; shelve = None; def __init__(self, dbname = 'phoneDat'): self.dbname = dbname; self.shelve = shelve.open(self.dbname); def __del__(self): self.shelve.close() self.shelve = None def add(self, name, number, type): e = phoneentry(name, number, type) self.shelve[str(e)] = e def lookup(self, string): lst = [] for key in self.shelve.keys(): e = self.shelve[key] if cmp(e, string) == 0: lst.append(e) return(lst); def printLst(self): for key1 in self.shelve.keys(): print self.shelve[key1].name + " "+self.shelve[key1].number + self.shelve[key1].typeOfNum; foo = phonedb() b = 1 print "Welcome to the Phone Database!" while(b != 3): print "Please make a selection by typing one of the following options." print "1.If you want to add an Employee type the #: 1" print"2.For a complete listing of Employees type the #: 2" print "3.To see the 'test page' and exit the Database type the #: 3" b = input(':') if b == 1: print "Enter the Employee's full name:" n = raw_input(':') print "Enter the Employee's full telephone number:" p = raw_input(':') print "Enter the telephone number type: (0 = UNKNOWN, 1 = HOME, 2 = WORK, 3 = FAX, 4 = CELL)" t = raw_input(':') if t == '0': foo.add(n, p, UNKNOWN) if t == '1': foo.add(n, p, "HOME") if t == '2': foo.add(n, p, "WORK") if t == '3': foo.add(n, p, "FAX") if t == '4': foo.add(n, p, "CELL") if b == 2: foo.printLst(); if b == 3: break;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote