Question Details Please include all proper indentions. You will be awarded 350 K
ID: 3619813 • Letter: Q
Question
Question DetailsPlease include all proper indentions.
You will be awarded 350 Karama Points!
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 'Second lookup:'
for entry in foo.lookup('e'):
print '%-40s %s (%s)' % ( entry.name, entry.number, entry.showtype() )
Explanation / Answer
Dear, Here is the remining code This code need to import the phoneentry and phonedb import sysfrom 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)
Hope this will help you... 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)
Hope this will help you...
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.