Simple python codes to make a simple library system
This code made by SAMALEN TV
class Book:
def __init__(self, title, author, isbn):
self.title = title
self.author = author
self.isbn = isbn
class Library:
def __init__(self):
self.books = []
def add_book(self, book):
self.books.append(book)
print("Book added successfully!")
def remove_book(self, book):
if book in self.books:
self.books.remove(book)
print("Book removed successfully!")
else:
print("Book not found.")
def display_books(self):
if not self.books:
print("No books in library.")
else:
print("List of books:")
for book in self.books:
print(f"{book.title} by {book.author} (ISBN: {book.isbn})")
library = Library()
while True:
print("1. Add book")
print("2. Remove book")
print("3. Display books")
print("4. Quit")
choice = input("Enter your choice: ")
if choice == "1":
title = input("Enter book title: ")
author = input("Enter book author: ")
isbn = input("Enter book ISBN: ")
book = Book(title, author, isbn)
library.add_book(book)
elif choice == "2":
title = input("Enter book title: ")
author = input("Enter book author: ")
isbn = input("Enter book ISBN: ")
book = Book(title, author, isbn)
library.remove_book(book)
elif choice == "3":
library.display_books()
elif choice == "4":
print("Goodbye!")
break
else:
print("Invalid choice. Try again.")
Run it to see results and Comment if anything wrong I will help you samalen Tv for you