-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlibrary.py
More file actions
58 lines (46 loc) · 1.88 KB
/
Copy pathlibrary.py
File metadata and controls
58 lines (46 loc) · 1.88 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
import book
class Library:
def __init__(self, books=None):
if books:
self.books = books
else:
self.books = []
def add_book(self, title, author, isbn, quantity):
new_book = book.Book(title, author, isbn, quantity)
self.books.append(new_book)
print(f"'{title}' added to the Library successfully.")
def remove_book(self, title_to_remove):
for book in self.books:
if title_to_remove.lower() in book.title.lower():
self.books.remove(book)
print(f"'{book.title}' removed from the Library successfully.")
return
raise ValueError(f"'{title_to_remove}' doesn't exist in the Library.")
def list_books(self):
if not self.books:
print("No books in the Library.")
return
print("List of Books:")
for index, book in enumerate(self.books, start=1):
print(f"{index}. {book.show_info()}")
def search_by_title(self, title):
for book in self.books:
if title.lower() in book.title.lower():
return book.show_info()
return "This book doesn't exist in the Library."
def return_book_by_title(self,title):
for book in self.books:
if title.lower() in book.title.lower():
return book
return "This book doesn't exist in the Library."
def search_by_author(self,author):
for book in self.books:
if author.lower() in book.author.lower():
return book.show_info()
return "This book doesn't exist in the Library."
def borrow_book(self,title):
for book in self.books:
if title.lower() in book.title.lower():
book.quantity -= 1
return f"You have successfully borrowed: {book.title}"
return f"{title} doesn't exist in the Library."