Python课程设计读者书库
时间: 2023-12-05 12:40:19 浏览: 88
根据提供的引用内容,Python课程设计读者书库是一个基于Python实现的项目,旨在帮助学生完成课程设计、毕业设计或练手项目。该项目的主要功能是实现一个读者书库,读者可以在其中添加、删除、修改和查询书籍信息。以下是该项目的一些功能和实现方法:
1. 添加书籍信息
```python
def add_book():
book_name = input("请输入书名:")
author = input("请输入作者:")
publisher = input("请输入出版社:")
price = input("请输入价格:")
with open("book.txt", "a") as f:
f.write(f"{book_name},{author},{publisher},{price}\n")
print("添加成功!")
```
2. 删除书籍信息
```python
def delete_book():
book_name = input("请输入要删除的书名:")
with open("book.txt", "r") as f:
lines = f.readlines()
with open("book.txt", "w") as f:
for line in lines:
if book_name not in line:
f.write(line)
print("删除成功!")
```
3. 修改书籍信息
```python
def modify_book():
book_name = input("请输入要修改的书名:")
with open("book.txt", "r") as f:
lines = f.readlines()
with open("book.txt", "w") as f:
for line in lines:
if book_name in line:
author = input("请输入作者:")
publisher = input("请输入出版社:")
price = input("请输入价格:")
f.write(f"{book_name},{author},{publisher},{price}\n")
print("修改成功!")
else:
f.write(line)
```
4. 查询书籍信息
```python
def query_book():
book_name = input("请输入要查询的书名:")
with open("book.txt", "r") as f:
lines = f.readlines()
for line in lines:
if book_name in line:
print(line.strip())
break
else:
print("未找到该书籍!")
```
阅读全文