i'm writing 2 classes
patron.py and
book.py i have a good chunk of what i need working i'm having a small problem and i'm sure it's probably syntactical or something just in the wrong place but either way i could really use some help.
what the program does is takes the class patron.py and book.py to keep track of who has checked out what book and how many books they have out and waiting lists for books if someone has it checked out but someone else wants it. that's the basic idea of what it should be doing.
now my problem comes in on the getting the program to borrow a book out to someone, so then it also has the problem of not keeping track of the # of books they have either this is the section of code i'm having trouble with
CODE
[color=#000099]def borrowMe(self, patron):
if self._borrower !=None:
print "you have been put on the waiting list for this book"
self._waitList.add(patron)
return False
elif self._borrower ==None:
if patron.getNumOfBooksOut()>=3:
print "you have too many books checked out already"
return False
else:
patron.self._booksOut+=1
print "You have successfully checked the book out"[/color]
this is how i begin to run it and the error that shows up:
CODE
[color=#33CC00]>>> patron1=Patron("Brandon", "Ramirez")
>>> book1=Book("Fundamentals of Python", "Kenneth A. Lambert")
>>> book1.borrowMe(patron1)[/color]
[color=#FF0000]Traceback (most recent call last):
File "<pyshell#120>", line 1, in <module>
book1.borrowMe(patron1)
File "C:\Python26\book.py", line 30, in borrowMe
patron.self._booksOut+=1
AttributeError: 'Patron' object has no attribute 'self'[/color]
now I know that self._booksOut is a problem but i can't really tell why or how to fix it. if any one can help i would really appreciate it!
i've posted the rest of my code below
CODE
[color=#000099]class Patron(object):
def __init__(self, fName, lName, ):
self._firstName = fName
self._lastName = lName
self._booksOut = 0
def getName(self):
return self._firstName+ " " +self._lastName
def getNumOfBooksOut(self):
return self._booksOut
def checkOut(self):
if self._booksOut<3:
self._booksOut +=1
return True
else:
return False
def returnBook(self, num):
self._numReturned = num
if 0<self._numReturned<=self._booksOut:
return True
booksOut-=self._numReturned
else:
return False
def __str__(self):
return patron1.getName() + " has " + str(self._booksOut) +\
" books checked out "[/color]
CODE
[color=#000099]from patron import Patron
class Book(object):
def __init__(self, title, author):
self._bookTitle = title
self._bookAuthor = author
self._waitList=()
self._borrower=None
def getTitle(self):
return self._bookTitle
def getAuthor(self):
return self._bookAuthor
def getPatron(self):
return self._borrower
def borrowMe(self, patron):
if self._borrower !=None:
print "you have been put on the waiting list for this book"
self._waitList.add(patron)
return False
elif self._borrower ==None:
if patron.getNumOfBooksOut()>=3:
print "you have too many books checked out already"
return False
else:
patron.self._booksOut+=1
print "You have successfully checked the book out"[/color]