图书管理系统借书还书伪代码Python
时间: 2023-11-29 20:44:43 浏览: 132
以下是一个简单的图书管理系统借书还书的伪代码Python示例:
```
# 定义一个Book类
class Book:
def __init__(self, title, author, ISBN, status):
self.title = title # 书名
self.author = author # 作者
self.ISBN = ISBN # ISBN号
self.status = status # 借阅状态
# 定义一个Library类
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 borrow_book(self, book):
if book.status == "available":
book.status = "borrowed"
print("借书成功!")
else:
print("这本书已经被借走了!")
# 还书
def return_book(self, book):
if book.status == "borrowed":
book.status = "available"
print("还书成功!")
else:
print("这本书已经在图书馆了!")
# 创建几本书
book1 = Book("Python编程从入门到实践", "Eric Matthes", "978-7-121-34084-6", "available")
book2 = Book("流畅的Python", "Luciano Ramalho", "978-7-121-34084-7", "borrowed")
book3 = Book("Python核心编程", "Wesley Chun", "978-7-121-34084-8", "available")
# 创建一个图书馆
library = Library()
# 将书籍添加到图书馆
library.add_book(book1)
library.add_book(book2)
library.add_book(book3)
# 借书
library.borrow_book(book1)
library.borrow_book(book2)
# 还书
library.return_book(book1)
library.return_book(book2)
```
阅读全文