、编写一个简单的图书馆里系统,能够实现图书的借阅,还书,查找,退出系统几项功能。假设图书馆有6本书。使用函数的方式。
时间: 2024-12-05 10:15:37 浏览: 10
我们可以创建一个简单的图书馆系统,主要包含几个核心函数来处理图书的相关操作:
1. 初始化图书列表:
```python
def initialize_library():
books = ['Book1', 'Book2', 'Book3', 'Book4', 'Book5', 'Book6']
return books
```
2. 借阅图书:
```python
def borrow_book(books, book_name):
if book_name in books and books.count(book_name) > 0:
books.remove(book_name)
print(f'{book_name}已成功借出。')
else:
print('对不起,这本书暂时无法借出。')
books = initialize_library()
borrow_book(books, 'Book1')
```
3. 还书:
```python
def return_book(books, book_name):
if book_name in books:
books.append(book_name)
print(f'{book_name}已成功归还。')
else:
print('这本书尚未借出,无需归还。')
return_book(books, 'Book1')
```
4. 查找图书:
```python
def search_book(books, book_name):
if book_name in books:
print(f'{book_name}在馆内。')
else:
print(f'{book_name}不在馆内。')
search_book(books, 'Book2')
```
5. 退出系统:
```python
def quit_system():
print('感谢您的使用,欢迎下次再来。')
exit()
quit_system()
```
阅读全文