当前位置:   article > 正文

Python课程设计:图书馆管理系统_python图书信息管理系统课设

python图书信息管理系统课设

图书馆管理系统:

基于python系统

引用库进行操作

系统主要实现:

  1. 添加书
  2. 删除书
  3. 借书
  4. 还书
  5. 查询图书信息
  6. 查询马上要归还的图书信息
  7. 按照借阅次序排序

源码简介:

  1. 对已图书信息进行更新操作,包括添加和删除一种书的信息,修改图书信息(例如图书被借阅,书的数目减1,借阅次数加1,如果数量为0则状态为不可借);
  2. 通过按图书的名称查询图书信息;
  3. 显示所有即将到期的图书进行排序;
  4. 将图书的所有相关信息内容存为文件。

源码运用:

运用到了python知识,在Python中,lambda函数是使用lambda表达式定义的单行匿名函数。它常用于将函数作为参数传递等场景。lambda函数具有lambda<参数>:<表达式>的格式。它没有函数名,函数体只有一条语句,这条语句的结果就是该函数的返回值。

整个代码中反复使用了for循环

[:-1]是python特有的切片操作,也叫切割操作,这里的下标0表示左起第一个元素,-1表示倒数最后一个元素。取一个list或tuple的部分元素是非常常见的操作

mode=”w+”表示即可以写数据又可以读取数据

<小总结>

用来应付大一大二python课程设计绰绰有余

以下代码仅供参考!并不完整!

可以私信

(全天25小时在线)

  1. import datetime
  2. book_info = ["索引", "名称", "地址", "类别", "数量", "价格", "入库时间", "归还时间", "次数", "状态"]
  3. book_info1 = [1, "红楼梦", "图书馆A1", "人文", 1, 22, datetime.datetime(2018, 1, 1), datetime.datetime(2018, 1, 1), 1, "可借"]
  4. book_info2 = [2, "西游记", "图书馆A2", "人文", 1, 22, datetime.datetime(2018, 1, 1), datetime.datetime(2018, 1, 1), 2, "可借"]
  5. book_info3 = [3, "水浒传", "图书馆A3", "人文", 1, 22, datetime.datetime(2018, 1, 1), datetime.datetime(2018, 1, 1), 3, "可借"]
  6. all_book_info = [book_info1, book_info2, book_info3]
  7. def add_book(_book_info, mode="a+"):
  8. f = open(r'lib.txt', mode)
  9. print(_book_info, file=f)
  10. f.close()
  11. def renew_books(_all_books):
  12. for index, _book in enumerate(_all_books):
  13. if index == 0:
  14. add_book(_book, mode="w+")
  15. else:
  16. add_book(_book)
  17. def read_books():
  18. f = open(r'lib.txt', "r")
  19. _books_info = f.read()
  20. _books_info_str = _books_info.split("\n")[:-1]
  21. _return_info = []
  22. for _book in _books_info_str:
  23. _return_info.append(eval(_book))
  24. f.close()
  25. return _return_info
  26. print("1.添加书")
  27. print("2.删除书")
  28. print("3.借书")
  29. print("4.还书")
  30. print("5.查询图书信息")
  31. print("6.查询马上要归还的图书信息")
  32. print("7.按照借阅次数排序")
  33. print("************")
  34. do_now = int(input("你想做什么呢?(输入为数字)"))
  35. # book_info = ["索引", "名称", "地址", "类别", "数量", "价格", "入库时间", "归还时间", "次数", "状态"]
  36. # datetime.datetime(2018, 1, 1)
  37. if do_now == 1:
  38. print("1.添加书")
  39. the_add_book = []
  40. for info in book_info:
  41. # int
  42. if info in ["索引", "数量", "价格", "次数"]:
  43. put_number = int(input(info + ":"))
  44. the_add_book.append(put_number)
  45. # datetime
  46. elif info in ["入库时间", "归还时间"]:
  47. put_date = input(info + ":(用逗号分开年月日)").split(",")
  48. the_add_book.append(datetime.datetime(int(put_date[0]), int(put_date[1]), int(put_date[2])))
  49. # str
  50. else:
  51. put_txt = input(info + ":")
  52. the_add_book.append(put_txt)
  53. add_book(the_add_book)
  54. elif do_now == 2:
  55. # 读取所有书
  56. all_book_info = read_books()
  57. # 把所有书名打出
  58. for _book in all_book_info:
  59. print(_book[1])
  60. del_book_name = input("你想删除哪一本书?")
  61. # stay_book -> 最后留下来的书
  62. stay_book = []
  63. for _book in all_book_info:
  64. if del_book_name != _book[1]:
  65. stay_book.append(_book)
  66. renew_books(stay_book)
  67. elif do_now == 3:
  68. # 读取所有书
  69. all_book_info = read_books()
  70. # 把所有书名打出
  71. for _book in all_book_info:
  72. if "不" not in _book[-1]:
  73. print(_book[1])
  74. borrow_book_name = input("你想借哪一本书?")
  75. for _book in all_book_info:
  76. if borrow_book_name == _book[1]:
  77. _book[4] = _book[4] - 1
  78. _book[-2] = _book[-2] + 1
  79. if _book[4] == 0:
  80. _book[-1] = "不可借"
  81. renew_books(all_book_info)
  82. elif do_now == 4:
  83. # 读取所有书
  84. all_book_info = read_books()
  85. # 把所有书名打出
  86. for _book in all_book_info:
  87. print(_book[1])
  88. return_book_name = input("你想还哪一本书?")
  89. for _book in all_book_info:
  90. if return_book_name == _book[1]:
  91. _book[4] = _book[4] + 1
  92. if _book[4] == 1:
  93. _book[-1] = "可借"
  94. renew_books(all_book_info)
  95. elif do_now == 5:
  96. # 读取所有书
  97. all_book_info = read_books()
  98. # 把所有书名打出
  99. for _book in all_book_info:
  100. print(_book[1])
  101. search_book_name = input("你想查询哪一本书?")
  102. for _book in all_book_info:
  103. if search_book_name == _book[1]:
  104. print(_book)
  105. renew_books(all_book_info)
  106. elif do_now == 6:
  107. all_book_info = read_books()
  108. # 把所有书名打出
  109. for _book in all_book_info:
  110. # datetime.datetime.now() ->获取当前日期
  111. if datetime.datetime.now() - _book[-3] > datetimetimedelta(days=3):
  112. print(_book[1], datetime.datetime.now() - _book[-3])
  113. elif do_now == 7:
  114. all_book_info = read_books()
  115. all_book_info.sort(key=lambda x: x[-2] * -1)
  116. for _book in all_book_info:
  117. print(_book[1])

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/811220
推荐阅读
相关标签
  

闽ICP备14008679号