Python图书管理系统大作业代码
时间: 2023-11-05 14:03:11 浏览: 39
抱歉,作为AI语言模型,我无法提供完整的Python图书管理系统大作业代码。但是,我可以为您提供一些相关的Python代码片段,以帮助您了解如何实现基本的图书管理系统功能。
1. 添加图书
```python
def add_book():
book_name = input("请输入书名:")
author = input("请输入作者:")
publisher = input("请输入出版社:")
price = float(input("请输入价格:"))
publish_date = input("请输入出版日期(格式为YYYY-MM-DD):")
book = {
"book_name": book_name,
"author": author,
"publisher": publisher,
"price": price,
"publish_date": publish_date
}
books.append(book)
print("添加成功!")
```
2. 查询图书
```python
def search_book():
book_name = input("请输入要查询的书名:")
result = []
for book in books:
if book["book_name"] == book_name:
result.append(book)
if len(result) == 0:
print("未找到相关书籍!")
else:
print("查询结果如下:")
for book in result:
print("书名:{},作者:{},出版社:{},价格:{},出版日期:{}".format(
book["book_name"], book["author"], book["publisher"], book["price"], book["publish_date"]))
```
3. 删除图书
```python
def delete_book():
book_name = input("请输入要删除的书名:")
for book in books:
if book["book_name"] == book_name:
books.remove(book)
print("删除成功!")
return
print("未找到相关书籍!")
```
4. 修改图书信息
```python
def modify_book():
book_name = input("请输入要修改的书名:")
for book in books:
if book["book_name"] == book_name:
book["author"] = input("请输入修改后的作者:")
book["publisher"] = input("请输入修改后的出版社:")
book["price"] = float(input("请输入修改后的价格:"))
book["publish_date"] = input("请输入修改后的出版日期(格式为YYYY-MM-DD):")
print("修改成功!")
return
print("未找到相关书籍!")
```
5. 显示所有图书
```python
def show_all_books():
print("所有图书信息如下:")
for book in books:
print("书名:{},作者:{},出版社:{},价格:{},出版日期:{}".format(
book["book_name"], book["author"], book["publisher"], book["price"], book["publish_date"]))
```
以上代码片段可以作为您构建图书管理系统的基础框架,但是需要根据具体需求进行修改和扩展。
阅读全文