Lost, Python Programming

Assignment Help:
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.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# You can contact Sean Reifschneider at
# P.O. Box 270624,
# Fort Collins, CO USA 80527-0624,
# or at [email protected]
#
# 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() )


Related Discussions:- Lost

Programming, We sell pdf''s from our site and pdfs can be ordered from the ...

We sell pdf''s from our site and pdfs can be ordered from the site by selecting a book, putting it in a shopping cart, then signing in with a password or as a guest, and then check

#title.display of vanderwaals isotherm, draw the variation of pressure with...

draw the variation of pressure with volume of a real gas at temperatures lower than its critical temperature.also draw its surface of discontinuity

Particle Movement, Imagine a "particle" located on the centre square of a t...

Imagine a "particle" located on the centre square of a two-dimensional grid of dimensions 11 by 75. The particle can only move one square at a time, either up, down, left, or right

Coding examples of python, Coding examples Following are some  attempts...

Coding examples Following are some  attempts at defining a function isSubset,  which  takes  two  arguments, a and  b, and  returns True if a is a subset  of b, assuming that

#cmdprobs, #Why can''t I cd my Desktop? A minute ago I would open up cmd an...

#Why can''t I cd my Desktop? A minute ago I would open up cmd and it starts in C:\Users\myname but now it''s starting in C:\WINDOWS\system> and I don''t where I am or how to get ou

Procedures as in First-class objects, Procedures as first-class objects ...

Procedures as first-class objects In Python, unlike  many  other  languages, methods are behave in much  the same way as num­ bers:  they  can be stored as values  of variable

Algorithms, Write an algorithm for the sum of the given series 1,-1/2,1/4,-...

Write an algorithm for the sum of the given series 1,-1/2,1/4,-1/8.....

Common Vulnerabilities, 1 Low Level Exploits 1.1 Savegames Jimmy is becomi...

1 Low Level Exploits 1.1 Savegames Jimmy is becoming increasingly frustrated at the computer game hes playing. He has a save right before the levels boss but he needs either more

Program requests password to display information of author, Write a program...

Write a program that requests a password after the author/program information is displayed. Make the password "hello". The program should then ask the user for their name: if the n

Turtle graphics module in python programming language, Your assignment for ...

Your assignment for the semester will involve the development of a system for drawing trees using the Python programming language and the turtle graphics module (turtle.py). Comple

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd