-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.py
More file actions
47 lines (36 loc) · 1.4 KB
/
Copy pathoop.py
File metadata and controls
47 lines (36 loc) · 1.4 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
class Library:
def __init__(self, books):
self.books = books
self.issuedBooks = []
def displayAvailableBooks(self):
print("Books present in this library are: ")
for book in self.books:
print(book)
def borrowBook(self, name):
borrow = input(f"Do you want to borrow {name}? (y/n): ")
if borrow == "y":
if name not in self.books:
print(f"{name} is not available")
elif name not in self.issuedBooks:
print(f"The book {name} has been successfully borrowed by you")
self.issuedBooks.append(name)
else:
print(f"The book {name} has already been issued to you")
else:
rtrn = input("Do you want to return this book? (y/n): ")
if rtrn == "y":
if name in self.issuedBooks:
print("You have successfully returned the book")
self.issuedBooks.remove(name)
else:
print(f"The book {name} is not issued to you")
def borrowedbooks(self):
print("Books issued to you are: ")
for book in self.issuedBooks:
print(book)
l1 = Library(["book1", "book2", "book3"])
l1.displayAvailableBooks()
while True:
book = input("Enter the name of the book: ")
l1.borrowBook(book)
l1.borrowedbooks()