python图书库存管理系统
时间: 2023-12-14 07:34:10 浏览: 144
以下是一个简单的Python图书库存管理系统的示例代码,它可以实现添加、删除、查找和显示图书信息等功能:
```python
class Book:
def __init__(self, title, author, publisher, ISBN, price, count):
self.title = title
self.author = author
self.publisher = publisher
self.ISBN = ISBN
self.price = price
self.count = count
class Library:
def __init__(self):
self.books = []
def add_book(self, book):
self.books.append(book)
def remove_book(self, book):
self.books.remove(book)
def search_book(self, title):
for book in self.books:
if book.title == title:
return book
return None
def display_books(self):
for book in self.books:
print("Title:", book.title)
print("Author:", book.author)
print("Publisher:", book.publisher)
print("ISBN:", book.ISBN)
print("Price:", book.price)
print("Count:", book.count)
print()
# 示例代码
library = Library()
book1 = Book("Python编程从入门到实践", "Eric Matthes", "人民邮电出版社", "9787115473765", 89.00, 10)
book2 = Book("Python基础教程", "Magnus Lie Hetland", "人民邮电出版社", "9787111599358", 69.00, 5)
library.add_book(book1)
library.add_book(book2)
library.display_books()
book3 = library.search_book("Python编程从入门到实践")
if book3:
library.remove_book(book3)
library.display_books()
```
阅读全文