Skip to content

Commit 37c0b0a

Browse files
committed
added project
1 parent 8b652a6 commit 37c0b0a

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

OOPs Library/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# OOPs Library Using Python🔥
2+
3+
Motive of this project is to create an “Online Library Management System.”
4+
5+
## 📌Let’s Create
6+
- Python has a large collection of libraries due to the very active community which serves various purposes.
7+
8+
For this Project, We have to create a library class that includes the following methods:
9+
10+
- Displaybook() : To display the available books
11+
- Lendbook(): To lend a book to a user
12+
- Addbook(): To add a book to the library
13+
- Returnbook(): To return the book to the library.
14+
15+
16+
As we have created a library class, now we will create an object and pass the following parameters in the constructor.
17+
18+
demo=Library(listofbooks, library_name)
19+
20+
After that, create a main function and run an infinite while loop that asks the users for their input whether they want to display, lend, add or return a book.
21+
22+
This is how we can build our OOPs Library with Python.
23+
Happy Coding!!

OOPs Library/oops_library.py

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
class Library:
2+
def __init__(self, list, name):
3+
self.booksList = list
4+
self.name = name
5+
self.lendDict = {}
6+
def displayBooks(self):
7+
print(f"We have following books in our library: {self.name}")
8+
for book in self.booksList:
9+
print(book)
10+
def lendBook(self, user, book):
11+
if book not in self.lendDict.keys():
12+
self.lendDict.update({book:user})
13+
print("Lender-Book database has been updated. You can take the book now")
14+
else:
15+
print(f"Book is already being used by {self.lendDict[book]}")
16+
def addBook(self, book):
17+
self.booksList.append(book)
18+
print("Book has been added to the book list")
19+
def returnBook(self, book):
20+
self.lendDict.pop(book)
21+
if __name__ == '__main__':
22+
demo = Library(['Python', 'Rich Daddy Poor Daddy', 'Harry Potter', 'C++ Basics', 'Algorithms by CLRS'], "Programmer")
23+
while(True):
24+
print(f"Welcome to the {demo.name} library. Enter your choice to continue")
25+
print("1. Display Books")
26+
print("2. Lend a Book")
27+
print("3. Add a Book")
28+
print("4. Return a Book")
29+
user_choice = input()
30+
if user_choice not in ['1','2','3','4']:
31+
print("Please enter a valid option")
32+
continue
33+
else:
34+
user_choice = int(user_choice)
35+
if user_choice == 1:
36+
demo.displayBooks()
37+
elif user_choice == 2:
38+
book = input("Enter the name of the book you want to lend:")
39+
user = input("Enter your name")
40+
demo.lendBook(user, book)
41+
elif user_choice == 3:
42+
book = input("Enter the name of the book you want to add:")
43+
demo.addBook(book)
44+
45+
elif user_choice == 4:
46+
book = input("Enter the name of the book you want to return:")
47+
demo.returnBook(book)
48+
else:
49+
print("Not a valid option")
50+
print("Press q to quit and c to continue")
51+
user_choice2 = ""
52+
while(user_choice2!="c" and user_choice2!="q"):
53+
user_choice2 = input()
54+
if user_choice2 == "q":
55+
exit()
56+
elif user_choice2 == "c":
57+
continue

0 commit comments

Comments
 (0)