要检查是否返回了以前的状态以便用户可以再次借阅图书,我们需要考虑以下几个方面:
以下是一个简单的示例代码,展示如何检查图书的借阅状态并允许用户再次借阅:
class Book:
def __init__(self, title, is_borrowed=False):
self.title = title
self.is_borrowed = is_borrowed
def borrow(self):
if not self.is_borrowed:
self.is_borrowed = True
print(f"{self.title} has been successfully borrowed.")
else:
print(f"Sorry, {self.title} is currently borrowed.")
def return_book(self):
if self.is_borrowed:
self.is_borrowed = False
print(f"{self.title} has been successfully returned.")
else:
print(f"Error: {self.title} was not borrowed.")
# 示例使用
book1 = Book("The Great Gatsby")
book1.borrow() # 输出: The Great Gatsby has been successfully borrowed.
book1.return_book() # 输出: The Great Gatsby has been successfully returned.
book1.borrow() # 输出: The Great Gatsby has been successfully borrowed.
通过上述方法和代码示例,可以有效检查图书的借阅状态,并确保用户在图书归还后可以再次借阅。关键在于维护准确的借阅状态和提供友好的用户界面。
领取专属 10元无门槛券
手把手带您无忧上云