用python做一个1. 系统登录注册(默认管理员账号为admin,密码为root) 2. 管理员可进行以下操作 1) 添加学生账户 2) 显示所有学生账户 3) 删除学生账户 4) 修改学生账户为黑名单 3. 登录成功进行图书管理系统(提示用户如下) 您已进入图书管理系统,请选择以下操作 1.查询图书(默认存在3本图书,书名自定义) 2.增加图书(书名相同无法新增,所以用户均可操作) 3.删除图书(仅限管理员操作) 3.借阅图书 1.图书不存在或已借出,则无法借阅 2.黑名单用户无法借阅 4.归还图书 5.退出系统 4.请使用面向对象编程
时间: 2024-03-18 11:40:27 浏览: 118
好的,这是一个比较完整的项目,需要一定的时间和精力去完成,我可以提供一些思路和代码实现的建议,但具体的实现需要您自己完成。首先,我们可以定义三个类,分别是管理员类、学生类和图书类。
管理员类:
```python
class Admin:
def __init__(self, username, password):
self.username = username
self.password = password
self.student_list = []
def add_student(self, student):
self.student_list.append(student)
def show_students(self):
for student in self.student_list:
print(student.name)
def del_student(self, student):
self.student_list.remove(student)
def add_blacklist(self, student):
student.is_blacklisted = True
```
学生类:
```python
class Student:
def __init__(self, name, password):
self.name = name
self.password = password
self.is_blacklisted = False
self.borrowed_books = []
def borrow_book(self, book):
if book.is_borrowed or self.is_blacklisted:
print("无法借阅此书")
else:
book.is_borrowed = True
self.borrowed_books.append(book)
def return_book(self, book):
if book.is_borrowed:
book.is_borrowed = False
self.borrowed_books.remove(book)
else:
print("此书未被借阅")
```
图书类:
```python
class Book:
def __init__(self, name):
self.name = name
self.is_borrowed = False
```
然后我们可以在主程序中实现系统登录和图书管理系统:
```python
def main():
admin = Admin("admin", "root")
student1 = Student("张三", "123456")
student2 = Student("李四", "123456")
student3 = Student("王五", "123456")
book1 = Book("Python编程从入门到精通")
book2 = Book("Java编程思想")
book3 = Book("C++ Primer Plus")
admin.add_student(student1)
admin.add_student(student2)
admin.add_student(student3)
books = [book1, book2, book3]
while True:
username = input("请输入用户名:")
password = input("请输入密码:")
if username == admin.username and password == admin.password:
print("登录成功")
break
else:
print("用户名或密码错误")
while True:
print("您已进入图书管理系统,请选择以下操作:")
print("1.查询图书")
print("2.增加图书")
print("3.删除图书")
print("4.借阅图书")
print("5.归还图书")
print("6.退出系统")
choice = input("请输入操作编号:")
if choice == "1":
for book in books:
if not book.is_borrowed:
print(book.name)
elif choice == "2":
book_name = input("请输入书名:")
book = Book(book_name)
if book in books:
print("该书已存在")
else:
books.append(book)
print("添加成功")
elif choice == "3":
if username == admin.username:
book_name = input("请输入要删除的书名:")
for book in books:
if book.name == book_name:
books.remove(book)
print("删除成功")
break
else:
print("该书不存在")
else:
print("您没有权限进行此操作")
elif choice == "4":
book_name = input("请输入要借阅的书名:")
for book in books:
if book.name == book_name:
student.borrow_book(book)
print("借阅成功")
break
else:
print("该书不存在或已被借出")
elif choice == "5":
book_name = input("请输入要归还的书名:")
for book in books:
if book.name == book_name:
student.return_book(book)
print("归还成功")
break
else:
print("该书不存在或未被借阅")
elif choice == "6":
break
else:
print("操作编号输入错误")
```
这只是一个简单的实现,您可以根据自己的需求进行修改和完善。希望对您有帮助!
阅读全文