Development of A Program in Python To Manage A Library
Development of A Program in Python To Manage A Library
to manage a library
Camilo Bernal
2. Analysis preliminary 2
3. Design basic 3
3.1. Module main. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.2. Module book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.3. Module partner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3.4. Module library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.5. Module validations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.6. Module menu. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4. Pseudo-code 6
4.1. Module main. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.2. Module book. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.3. Module partner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
4.4. Module library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
4.5. Module validations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4.6. Module menu10
5. Code Python13
5.1. Module main13
5.2. Module book13
5.3. Module socio14
5.4. Module library15
5.5. Module validations23
5.6. Module menu26
6. Conclusions 31
7. Readings recommended 32
I
1. Introduction
The first thing to clarify is that I am not an expert in programming nor much
less. If you are a beginner (like me) this manual can help you. If you are an expert,
perhaps it will only help you learn how "not to do things like a beginner."
1
2. Preliminary analysis
The library initially has no books, so it will acquire them through donations.
actions or purchases. The possibility of starting by lending a single book and simulating is proposed.
the passage of time through a random variable. When the program works, it
it will expand for the management of multiple books.
It is recommended to do incremental programming work, that is, to gradually carry out tasks.
small changes to the program and call the interpreter again for debugging tasks,
so that when the task is completed, there is not an unknown number of errors.
One of the greatest frustrations I have personally experienced while creating programs is
relates to mental blockage when faced with an excessive amount of code and exceptions. It
What I recommend is to create a preliminary design and write all the pseudocode. Before
writing a single line of code, it is very convenient to have perfectly clear how
solve the problem; this little trick will save many hours of work and much
frustration.
2
3. Basic design
The program will be built in modules, in order to prevent individual files from having
an excessive amount of code.
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Define main function
Explain what it does
Insatnaitet hteLbirarycals ofthe<maneoj_bbioiletca>moduel
Insatnaitehtecals Choosefromthe<menu>moduel
Deploy the options to interact with the user
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Book
Explain what it does
Initialize
Build a method to show atributes
3
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Socoi (nihesrti fromBook)
Explain what it does
Initialize
Build method to show atributes
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Lbirary(Inhesrti fromBookandMember)
Explain what it does
Initialize
Build method showAvailableBooks
Build method showBorrowedBooks
construct method lendBook
construct method receive Book
construct method receiveDonation
construct method buyBook
Build method showMembers
Build method showDelinquentMembers
Build method showMembersWithoutBooks
Build method showMembersWithBooks
Build method to affiliate member
Build a method to unaffiliate a member
construct method show attributes
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Vadilaotr
Explain what it does
initialize
Build method validateTitle
Build method validateAuthor
Construct method validateEdit
Build method validateName
construct method validateID
Build method validateChoice
Build method to show atributes
4
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Choose
Explain what it does
Initialize
Construct method deployOptions
Construct method executeOption
Construct method showAvailableBooks
Construct method showBorrowedBooks
Build method elPrestarLibro
Build method elRecibirLibro
Build method elDonarLibro
Build method elComprarLibro
Build method elMostrarSocios
Construct method showMembersWithoutBooks
Build method showMembersWithBooks
Build method elMostrarSociosMorosos
Build method and affiliate partner
Build method to disaffiliate member
Build method s a l i r
Build method show atributes
5
4. Pseudocode
Once the basic design is completed, one can start writing the pseudo-code. To
this is sufficient to use the previous design and start making small additions,
that will serve as clues and will prevent mental blockage later on.
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Define main function
Insatnaitet hteLbirarycals ofthe<bilrary>moduel
Insatnaitehtecals Choosefromthe<menu>moduel
Deploy options to interact with the user
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Book
Allows building an object with the attributes of a
book
initialize
Initializing title
initialize author
Initialize edition
Initialize state
Build a method to show atributes
Show the object's attributes with a brief
description
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Socoi()
Allows to construct an object with the attributes and
methods of a partner of library
to initialize
Initialize name
Initial ID
Initialize state
6
Iinitializebooks
Initializing Penalty
Build method to show atributes
Show atributes with a brief description
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Lbirary(Inhesrti fromBook,Memberand\
Validations
Allows constructing an object with the attributes and
methods of a library
Initialize
Initialize the list of available books
Initialize the list of borrowed books
Initialize the list of members_without_books
Initialize the list of members_with_books
Initialize the list of delinquent members
Build method showAvailableBooks
If the available books has books:
Show books with cycling for
Build method showBorrowedBooks
If borowed_bookshasbooks:
Show borrowed books with cycle for
construct method lendBook()
Chooseapanrteratrandom
Indciaet htetelti ofthebookyouwsihto borow
Cary outthegeneralverifcationprocess
If you meet all the requirements, press the \
book
7
c o n s t r u i r method buyBook
Request title attributes of the book
Assign status = available
Insatnaitet bookobejctwhti requesetddaat
addinstantiatedobjectto available_books
Build method showMembers
start cycle for on the list socios_con_libros+
members_whtiou_tbooks+denilquen_tmembers
show atributes of the partner for each one
Build method showDelinquentMembers
start the cycle for the list of delinquent members
showmemberatributes
Build method showMembersWithoutBooks
initialize cycle for the list socios_sin_libros
showmemberatributes
Build method showMembersWithBooks
start cycle for the list socios_con_libros
showmemberatributes
Build method to affiliate member
Request name
Request ID
Assign status = normal
Assign books = [ ]
Assignpenalty =0
Instantiate thesocio objectwith therequesteddata
Inrtoduceobejctinparnters_whtiou_tbooks
Build method of un-affiliating member
Request ID
start cycle for partners_without_books
Ifyoufnidyourseflni panrters_whtiou_tbooks:
exratctobejctfrompanrters_whtiou_tbooks
return
start cycle for about partners_with_books
If found in partners_with_books:
Inform that you must return the books first.
what does it have to be able to un-subscribe
return
start the cycle for delinquent partners
If you are in delinquent_partners:
Inform that you are on the list of delinquent members
and that you must wait 10 days before
rty ot unasocaiet onesefl
8
exrtactmemberfromdenilquen_tmembers
changethesatutsartbiuet ofthememberobejctto normal
introduce member to members_without_books
return
If not found:
Inform that the corresponding ID was not found.
nrehteoprat
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Vadilaotr
Allows you to create objects that validate the inputs of
Initialize
initialize_validateTitle
Initialize_validateAuthor
initialize_validateEdit
initialize_validateName
initialize_validateID
Build method validateTitle
The title must have at least 4 characters
If the tile has at least four characters
e_validateTitle is True
Who
Notify that the title is not valid.
Build method validateAuthor
The author must have at least 4 characters
If the tile has at least four characters
e_validarAutor is worth True
Who
Notify that the author's name is not valid.
Build method validateEditon
The edition number is a positive integer.
Initialize states es_entero, es_positivo to False
Trytoconverttointeger
If it can be done, is_integer is True
If it is integer, verify if it is positive
Iftisi posvite,is_posviteissettoTrue.
If both conditions are met:
9
e_validarEdicion vale True
Who
Notify that the edition number is not valid.
Build method validateName
The name must have at least 4 characters
If the name has at least 4 characters
validateName is valid True
Who
Notify that the partner's name is not valid.
construct method validateID
ID is a positive integer of at least 5 digits
Initialize states is_integer, is_positive, has_5c_\
o_mas aFalse
Trytoconvertintoaninteger
If it is possible, is_integer is True
If it is an integer, check if it is positive
If it is positve, is_positve is True
If the length is at least 5
has_5c_or_more is True
If the three conditions are met:
e_validateID is worth True
Sino:
Notify that the member ID is not valid.
construct validationMethodChoice
The selection must be an integer between 1 and 13
construct method show attributes
show atributes with a brief description
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Defniecals Choose
Initialize
initialization option
10
Build method executeOption
Execute the chosen option and return to elDesplegar
Options
11
Show the members who have books on loan
invoke the method mostrarSociosConLibros of the object
library
12
5. Python Code
I think it's not useless to repeat it: Code is written ONLY when you already have it.
any idea on how to solve the problem and if a solution has been proposed with some
clarity. Jumping into writing code thoughtlessly is the perfect recipe for the
frustration: I hope they don't make that mistake.
Functionthatallowscallingothercomponentsofthe
program to manage a library
main()
#! /usr/bin/env python
The provided text does not contain any translatable content.
class Book () :
13
Allows constructing an object with the attributes of a book
Initializing
def __init__(self, title, author, edition_number, status='available'):
title
[Link] = author
self.n_edicion = n_edicion
[Link] = state
Allows constructing an object with the attributes and methods of a library member
Initialize
def __init__(self, name, ID, status = 'normal', books = [], penalty = 0):
[Link] = name
[Link] = ID
[Link] = state
[Link] = books
penalization
14
Penalty:
return s
import random
import validations
from book import Book
from s o c i o import Socio
Define class Library()
class Bibliotec (Book, Member, validations. Validator):
Initialize
def __init__(self):
self.libros_disponibles=[]
s e l f .libros_prestados = [ ]
self.socios_sin_libros=[]
s e l f .socios_con_libros = [ ]
self.socios_morosos = [ ]
15
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−\n"
Press ENTER to continue
raw_input()
16
raw_input()
return
If it is a delinquent partner
the socio_moroso:
Indicate to the partner that they are in default, and that they must
17
Press ENTER to continue
raw_input()
self.socios_con_libros.remove(socio)
Remove the book from the books attribute of the member object.
s o c i o . l i b r o s . remove ( b o o k )
18
I introduce social partners without books do not have books
in another case, introduce it in partners_with_books
if len([Link]) == 0:
self.socios_sin_libros.append(socio)
else:
self.socios_con_libros.append(socio)
prnit"\nEllibrorecibidoes:",[Link]
prnit"Theparnterwhodevileredit si:",[Link]
Final reception process completed
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Press ENTER to continue
raw_input()
19
Instantiate object book with requested data
new_book=Book(title,author,edition_number)
Add instantiated object to available_books
self.available_books.append(new_book)
Thanking
Thankyouvery muchforyourdonaoitn.
Thebookwlibeavaalibel fortheservcieofthecommunyti
Press ENTER to continue
raw_input()
20
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Thedenilquentmembers havebeenchosento beshown
if len(self.socios_morosos) > 0:
for iin self. bad_debtors:
prniti
else:
***There are nodelinquentmembers
Final visualization process completed
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Press ENTER to continue
raw_input()
21
new_member
Introducing object in partners_without_books
self.socios_sin_libros.append(nuevo_socio)
Finalization process completed
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Press ENTER to continue
raw_input()
22
for self. borrowed_books :
s += s t r ( i )
−∗−∗−∗−∗−∗−∗−∗−∗−∗−∗−∗−"
Partners without books:
for myself. socio_sin_books:
s += s str(i)
−∗−∗−∗−∗−∗−∗−∗−∗−∗−∗−∗−"
Members with books:
for self. partners_with_books:
s += s t r ( i )
−∗−∗−∗−∗−∗−∗−∗−∗−∗−∗−∗−"
Late members:
for in self. delinquent_members:
s += s str(i)
return s
Initialize
def __init__(self):
self.e_validateTitle = False
self.e_validateAuthor = False
False
[Link] = False
self.e_validateID = False
s e l f .e_validarEleccion = False
23
else:
The authors' name is not valid
Remember that you must have at least 4 characters
self.e_validateAuthor = False
return self.e_validateAuthor
24
es_entero=True
excep:t
Notify that the member ID is not valid
TheenetredmemberID si nicorec.t
Remember that it must be a positive integer of at least
5cifras
self.e_validarID = False
return s e l f . e_validarID
If it is an integer, check if it is positive.
if ID > 0:
If it is positive, is_positive is True
es_positvo=True
If the length is at least 5
if len(str(ID)) >= 5:
# tiene_5c_o_mas vale True
tiene_5c_o_mas = True
If it meets the three conditions:
if is_integer and is_positive and has_5_or_more:
#e_validarID is True
self.e_validateID = True
else
Notify that the ID of the partner is not valid.
TheenetredmemberID si nicorec.t
Remember that it must be a positive integer of at least
5 digits
self.e_validateID = False
return selfe._validateID
25
Show attributes with a brief description
Validator object attributes
s += " Book title status: " + str(self.e_validarTitulo)
Author status of the book:
State of the book's edition:
s += "\nStatus of Member's Name: " + str(self.e_validateName)
s += "\nMember ID status: " + str(self.e_validarID) + "\n"
return s
Initializar
def __init__(self, library):
[Link] = biblioteca
s e l f .opcion = 13
Build method deployOptions
def displayOptions(self):
Show the options that the user has
=======================
prni−
t −−−−−−−−−−LIBRARY MANAGEMENT−−−−−−−−−−−−−−"
"======================="tnirp
Please choose an option:
print"\n1− − −Show available books
2− − −Show borrowed books
3− − −To l e n d a b o o k
4− − −R e c e i v e b o o k
print"5− − −R e c e i v e d o n a t i o n
pnrit"6"− − −Buy book
print"7− − −Show partners
8− − −Show partners without books
pnrit"9"− − −Show members with books
10− − −Show delinquent members
prni"t11− − −a familiar socio
prni"t12− − −To desafiary socio
prni"t13− − −SALR
I
26
while True :
EnteroptionandpressENTER:
input()
if [Link](option): break
[Link] = int(option)
[Link]()
if [Link] != 13:
[Link]()
Build method executeOption
def executeOption(self):
if [Link] == 1:
[Link]()
else if [Link] == 2:
[Link]()
elif [Link] == 3:
[Link]()
if [Link] == 4:
[Link]()
if [Link] == 5:
[Link]()
if [Link] == 6:
[Link]()
if [Link] == 7:
s e l f .elShowPartners ()
if [Link] == 8:
[Link]()
elif [Link] == 9:
[Link]()
elif [Link] == 10:
[Link]()
else [Link] == 11:
[Link]()
if [Link] == 12:
s e l f . e l D e s a f i l i a r S o c i o()
if [Link] == 13:
[Link]()
27
Build method elMostrarLibrosPrestados
defshowBorowedBooks(self):
Allows showing the books lent to the members
invoke the method showBorrowedBooks of the object library
[Link]()
28
[Link]()
29
Option:
Attributes of the instantiated library object:
s += str([Link])
return s
30
6. Conclusions
31
7. Recommended readings
There are several good manuals online. Personally, I recommend that you search on
google the PDF files with the following titles:
32