-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.py
More file actions
executable file
·105 lines (86 loc) · 2.81 KB
/
Copy pathlibrary.py
File metadata and controls
executable file
·105 lines (86 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#! /usr/bin/env python
from string import ascii_uppercase
class Library(object):
"""docstring for Library"""
def __init__(self):
self.shelves = []
def add(self, shelf):
if shelf not in self.shelves:
self.shelves.append(shelf)
def show(self):
print "Shelf:".ljust(20), "Title:".ljust(20), "Author:".ljust(20)
for i in self.shelves:
y = i[6]
for x in eval("shelf{0}.books".format(y)):
print i.ljust(20), x[0].ljust(20), x[1].ljust(20)
class Shelf(object):
"""docstring for Shelf"""
def __init__(self):
self.books = []
def add(self, book):
self.books.append(book)
def rem(self, title):
for i in self.books:
if title not in i:
pass
else:
self.books.pop(self.books.index(i))
break
else:
print "Can't checkout {0}{1}{2}{0} Book is not in Library".format('"', title, '.')
def show(self):
print "".ljust(20), "Title:".ljust(20), "Author:".ljust(20)
for i in sorted(self.books[:]):
print "".ljust(20), i[0].ljust(20), i[1].ljust(20)
class Book(object):
"""docstring for book"""
def __init__(self, title, author):
self.title = title
self.author = author
self.title_author = (self.title, self.author)
def enshelf(self):
x = self.author[0]
eval("shelf{0}.add(self.title_author)".format(x))
def unshelf(self):
x = self.author[0]
eval("shelf{0}.rem(self.title)".format(x))
def show(self):
print "".ljust(20), "Title:".ljust(20), "Author:".ljust(20)
print "".ljust(20), self.title.ljust(20), self.author.ljust(20)
Library1 = Library()
alpha = list(ascii_uppercase)
for i in alpha:
exec("shelf{0} = Shelf()".format(i))
x = "shelf {0}".format(i)
Library1.add(x)
A = Book("Dune", "Herbert, Frank")
B = Book("Iberia", "Michener, James A")
C = Book("Jitterbug Perfume", "Robbins, Tom")
D = Book("Iberia", "Michener, James A")
E = Book("Alaska", "Michener, James A")
F = Book("Jitterbug Perfume", "Robbins, Tom")
G = Book("Centennial", "Michener, James A")
A.enshelf()
B.enshelf()
C.enshelf()
D.enshelf()
E.enshelf()
F.enshelf()
library1 = Library()
print
print "\033[4mShowing Library Status\033[0m" "\n"
Library1.show()
print "\n" * 2
print "\033[4mChecking {0}{1}{0} out of the Library\033[0m".format('"', A.title), "\n" * 3
A.unshelf()
print "\033[4mShowing Library Status after Checkout of {0}{1}{0}\033[0m".format('"', A.title), "\n"
Library1.show()
print "\n" * 2
print "\033[4mChecking {0}{1}{0} out of the Library\033[0m".format('"', G.title), "\n"
G.unshelf()
print "\n" * 2
print "\033[4mShowing Shelf M\033[0m" "\n"
shelfM.show()
print "\n" * 2
print "\033[4mShowing Book A\033[0m" "\n"
A.show()