Project Level 2: Intermediate
This project is designed for intermediate learners who know Python fundamentals and are practicing building complete programs.
Project Description
For today’s project, the task is to build a console-based book lending system for a small library or a personal book collection. This app allows users to browse available books, borrow a book, return a book, and view all borrowed books.
The user can choose option 1 to view available books for borrowing:
The user can choose 2 and then enter the number of the book they want to borrow:
The user can choose 3 to return a book so the book becomes available again for borrowing:
👉 We challenge you to use classes (i.e., OOP) instead of functions this time. Here is how the code would look like. You can complete the rest yourself.
class BookLendingSystem:
def __init__(self):
self.available_books = {
1: "The Great Gatsby",
2: "To Kill a Mockingbird",
3: "1984",
4: "Pride and Prejudice"
}
self.borrowed_books = {}
def display_menu(self):
print("\nWelcome to the Book Lending System!")
...
...
def view_available_books(self):
...
...
def borrow_book(self):
if not self.available_books:
...
...
def return_book(self):
if not self.borrowed_books:
...
...
def view_borrowed_books(self):
if not self.borrowed_books:
...
...
def run(self):
while True:
self.display_menu()
choice = input("\nChoose an option: ").strip()
if choice == "1":
...
...
system = BookLendingSystem()
system.run()
Learning Benefits
You will practice managing lists and dictionaries, handling user input, and implementing logical workflows for an interactive application. In addition, you will practice working with classes.
Prerequisites
Required Libraries: No libraries are needed for this project.
Required Files: No files are needed for this project.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Once you code the project, compare it with our two solutions given in the button below.