精华内容
下载资源
问答
  • python图书管理系统

    2020-09-20 17:38:45
    主要为大家详细介绍了python图书管理系统的实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • Python图书管理系统

    2018-07-04 22:53:05
    一个基于Python图书管理系统, 主要实现书籍的增删改查。
  • python+简单的图书管理系统源码
  • 使用Django编写的图书管理系统。 如何使用 可以先安装pyenv管理python版本的 可以百度如何安装pyenv 之后就可以在电脑上安装多个python版本,随意切换 切换python版本到3.4.2切换python版本到3.5.2 pyenv local ...
  • 0 465 2019-12-06 14:02 − 学习提纲 生成指定范围的数值列表,语法格式如下: 生成一个包括10哥随机数的列表,要求数的范围在10-100之间,代码如下 import random randomnumber = [random.randint(10,100) for i ...

    原博文

    2018-12-11 10:59 −

    1 #缺少循环执行和错误处理 2 #add()函数 添加了循环执行 3 #错误处理:regist()函数 登录和退出选择的时候添加了错误处理 4 import sys 5 import importlib 6 importlib.reload(sys) 7 Book=[['高数','...

    comment.png

    0

    attention.png

    1729

    相关推荐

    2019-09-28 21:13 −

    Python python是一种跨平台的计算机程序设计语言,是一种面向对象的动态类型语言。 最初被设计用于编写自动化脚本(shell),随着版本的不断更新和语言新功能的添加,越来越多被用于独立的、大型项目的开发。(以上摘自百度百科) Python是一种解释型脚本语言,可以应用于以下领域...

    comment.png

    0

    attention.png

    1961

    2019-12-24 19:55 −

    1 Web应用 https://www.cnblogs.com/yuanchenqi/articles/8869302.html2 http协议 https://www.cnblogs.com/yuanchenqi/articles/8875623...

    2019-12-04 22:39 −

    是不是看到题目Python就点进来了。

    其实,只是个蒟蒻......

    不知道学校发了什么疯,现在连普通的信息课都在讲Python,是怕我们消化不了c++吗?

    虽然心里很不甘心,但不得不承认,许多时候(实际上是大部分),Python都比c++更简单。

    原因:

    1.Python不用打头文件(咳咳,纯属个...

    comment.png

    0

    attention.png

    465

    2019-12-06 14:02 −

    学习提纲

    生成指定范围的数值列表,语法格式如下:

    生成一个包括10哥随机数的列表,要求数的范围在10-100之间,代码如下

    import random

    randomnumber = [random.randint(10,100) for i in range(...

    2019-12-18 15:00 −

    保留字:and,as,assert,break,class,continue,

    def,del,elif,else,except,finally,

    forfromFalse,global,if,import,

    in,is,lambda,nonlocal,not...

    comment.png

    0

    attention.png

    181

    2019-12-24 21:14 −

    python-requests

    python-requests

    作用:能够模拟浏览器向服务器发送请求的库

    requests库的主要方法

    方法描述

    requests.request()构造一个请求,支持以下各种方法requests.get()获取html的主要方法requests.head(...

    comment.png

    0

    attention.png

    525

    2019-12-11 17:16 −

    Redis

    redis是一个key-value存储系统。

    赋值:set name alex查看所有key:keys *查看key对应的value:get name只存活2秒钟:set name jack ex 2

    Python操作Redissudo pip install redis

    1、操作模式r...

    2019-11-27 16:55 −

    1.安装

    需要安装得模块名为pyyaml,直接pip install pyyaml

    导入,直接import yaml

    2.yaml文件的格式

    文件格式输出可以是列表,可以是字典,可以嵌套。层级关系用空格区分,切记,不支持tab缩进

    a)键值对形式

    user: admin

    pwd: 123

    ...

    2019-11-23 12:52 −

    # Python3随手记 - [Python3随手记](#python3%e9%9a%8f%e6%89%8b%e8%ae%b0) - [list方法](#list%e6%96%b9%e6%b3%95) - [os](#os) - [imageio](#imageio) - [Python I...

    展开全文
  • 基于python设计的图书管理系统源码文件.可以做为你的学习设计参考。
  • python 图书管理系统

    2020-02-18 14:59:53
    python 图书管理系统 # 示例代码 books=[ {"bookname":"红楼梦","numbers":2}, {"bookname":"西游记","numbers":3}, {"bookname":"三国演义","numbers":2}, {"bookname":"水浒传","numbers":2}, {"bookname":...

    python 图书管理系统

    # 示例代码
    
    books=[
       {"bookname":"红楼梦","numbers":2},
       {"bookname":"西游记","numbers":3},
       {"bookname":"三国演义","numbers":2},
       {"bookname":"水浒传","numbers":2},
       {"bookname":"龙王传说","numbers":2},
       {"bookname":"绝世唐门","numbers":3}
    ]
    students=[
       {"id":"101","password":"123","name":"张三","books":["红楼梦","龙王传说"]},
       {"id":"102","password":"123","name":"李四","books":["红楼梦","三国演义"]},
       {"id":"103","password":"123","name":"王五","books":["水浒传","西游记"]},
       {"id":"104","password":"123","name":"赵六","books":["红楼梦","水浒传"]},
       {"id":"105","password":"123","name":"小明","books":["三国演义","龙王传说"]},
    ]
    def id_book(id):
       for dict_stu in students:
          if dict_stu["id"]==id:
             return dict_stu["books"]      
    def lend_book(book):
       stu_books=id_book(user_name)
       if len(stu_books)==5:
          print("只能借5本")
          return
       for dict_book  in books:
          if book == dict_book["bookname"]:
             if book in stu_books:
                print("您已借过这本书")
                print(id_book(user_name))
             else:
                if dict_book["numbers"]==0:
                   print("这本书已借光")
                   print(dict_book)
                   return
                for dict_stu in students:
                   if dict_stu["id"]==user_name:
                      dict_stu["books"].append(book)
                      print(id_book(user_name))
                      dict_book["numbers"]-=1
                      print(dict_book)
             break
       else:
          print("没有这本书") 
    def repay_book(book):
       stu_books=id_book(user_name)
       if book in stu_books:
          stu_books.remove(book)
          for dict_book  in books:
             if book == dict_book["bookname"]:
                dict_book["numbers"]+=1
                print(dict_book)
          print(id_book(user_name))
       else:
          print("您没有这本书")
          print(id_book(user_name))
    def change_password():
       old_passwd=input("请输入原密码")
       new_passwd=input("请输入新密码")
       new_passwd1=input("请再次输入新密码")
       if old_passwd!=get_password(user_name):
          print("原密码错误")
          return
       elif new_passwd1!=new_passwd:
          print("两次新密码输入不一致")
          return
       elif len(new_passwd)<6:
          print("请输入长度大于6的新密码")
          return
       else:
          for dict_stu in students:
             if dict_stu["id"]==user_name:
                dict_stu["password"]=new_passwd
          print("修改成功")
    def success_login():
       while True:
          choice=input("1.借书 2.还书 3. 修改密码 4.退出")
          if choice=="1":
             book=input("请输入您要借的书名")
             lend_book(book)
          elif choice=="2":
             book=input("请输入你要还的书")
             repay_book(book)
          elif choice=="3":
             change_password()
          elif choice=="4":
             print("退出个人图书管理系统成功")
             print("已进入登录界面")
             login()
             break
    def get_password(id):
       for dict_stu in students:
          if dict_stu["id"]==id:
             return dict_stu["password"]
    def login():
       global n,user_name,pass_word
       user_name=input("请输入您的id")
       pass_word=input("请输入你的密码")
       if n>2:
          print("您的账号已锁定")
          return
       if user_name=="退出":
          return
       if pass_word==get_password(user_name):
          print("登录成功")
          success_login()
       else:
          print("登录失败请重新登录")
          n+=1
          login()
    n=0
    user_name=""
    pass_word=""
    login()
    
    
    
    展开全文
  • python编写图书管理系统python编写图书管理系统python编写图书管理系统
  • 主要为大家详细介绍了python实现图书管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
  • 本文实例为大家分享了python实现图书管理系统的具体代码,供大家参考,具体内容如下import mysql.connectorimport sys, osimport timeimport datetimefrom tkinter import *from tkinter.messagebox import *class ...

    本文实例为大家分享了python实现图书管理系统的具体代码,供大家参考,具体内容如下

    import mysql.connector

    import sys, os

    import time

    import datetime

    from tkinter import *

    from tkinter.messagebox import *

    class Libop:

    user = "root"

    pwd = ""

    host = "localhost"

    db = "library"

    data_file = "mysql-test.dat"

    def __init__(self):

    print("init")

    try:

    self.library=mysql.connector.connect(user=Libop.user,password=Libop.pwd,host=Libop.host,database=Libop.db)

    self.cursor=self.library.cursor()

    print("Connect successfully")

    except mysql.connector.Error as err:

    print("WTF! initial wrong")

    print("Error: {}".format(err.msg))

    sys.exit()

    def select(self,str):

    try:

    self.cursor.execute(str)

    return self.cursor.fetchall()

    except mysql.connector.Error as err:

    print("WTF! select wrong")

    print("Error:{}".format(err.msg))

    print(str)

    showinfo("ERROR","Please input the parameter correctly")

    def update(self,str):

    try:

    self.cursor.execute(str)

    self.library.commit()

    return 1

    except mysql.connector.Error as err:

    print("WTF! update wrong")

    print("Error:{}".format(err.msg))

    return 0

    def delete(self,str):

    try:

    self.cursor.execute(str)

    self.library.commit()

    except mysql.connector.Error as err:

    print("WTF! delete wrong")

    print("Error:{}".format(err.msg))

    def insert(self,str):

    try:

    self.cursor.execute(str)

    self.library.commit()

    return 1

    except mysql.connector.Error as err:

    print("WTF! insert wrong")

    print("Error:{}".format(err.msg))

    return 0

    LIB = Libop()

    root=Tk()

    root.wm_title("Library System")

    str1=str2=""

    book_type=name=year=publisher=writer=price1=price2=order=""

    cardid=""

    def call_rent(en1,en2,brok):

    st1=en1.get()

    st2=en2.get()

    rent(st1,st2,brok)

    def call_return(en1,en2):

    st1=en1.get()

    st2=en2.get()

    back(st1,st2)

    def login():

    str1=ide.get()

    str2=pwde.get()

    curs=LIB.select("select manage_id,pswd from managers where manage_id="{}" and pswd="{}"".format(str1,str2))

    if ((str1,str2) in curs):

    showinfo("message","login success")

    label_book_id=Label(root,text="BookID:").grid(row=0,column=4,sticky=W)

    label_card_id=Label(root,text="CardID:").grid(row=1,column=4,sticky=W)

    entry_book_id=Entry(root)

    entry_book_id.grid(row=0,column=5,sticky=W)

    entry_card_id=Entry(root)

    entry_card_id.grid(row=1,column=5,sticky=W)

    entry_cardid=Entry(root)

    entry_cardid.grid(row=5,column=0,sticky=W)

    #buttons

    button_insert=Button(root,text="insert book",command=inbook)

    button_insert.grid(row=0,column=2,sticky=W)

    button_return=Button(root,text="rent book")

    button_return.bind("",lambda z:call_rent(entry_book_id,entry_card_id,str1))

    button_return.grid(row=0,column=3,sticky=W)

    button_rent=Button(root,text="return book")

    button_rent.bind("",lambda l:call_return(entry_book_id,entry_card_id))

    button_rent.grid(row=1,column=2,sticky=W)

    button_delete=Button(root,text="delete card")

    button_delete.bind("",lambda j:deletecard(entry_cardid))

    button_delete.grid(row=5,column=2,sticky=W)

    button_add=Button(root,text="add card",command=addwindow)

    button_add.grid(row=5,column=3,sticky=W)

    button_display=Button(root,text="display books")

    button_display.bind("",lambda y:display_rent(entry_cardid))

    button_display.grid(row=5,column=1,sticky=W)

    else:

    showinfo(title="login failure",message="WRONG ID OR PASSWORD!")

    #add a card

    def addwindow():

    top=Toplevel(root)

    label_card_id=Label(top,text="card id:").grid(row=0,column=0,sticky=W)

    label_name=Label(top,text="Name:").grid(row=1,column=0,sticky=W)

    label_unit=Label(top,text="Units:").grid(row=2,column=0,sticky=W)

    label_type=Label(top,text="type:").grid(row=3,column=0,sticky=W)

    entry_card_id=Entry(top)

    entry_card_id.grid(row=0,column=1,sticky=W)

    entry_name=Entry(top)

    entry_name.grid(row=1,column=1,sticky=W)

    entry_unit=Entry(top)

    entry_unit.grid(row=2,column=1,sticky=W)

    entry_type=Entry(top)

    entry_type.grid(row=3,column=1,sticky=W)

    button_constructe=Button(top,text="Add")

    button_constructe.bind("",lambda q:addcard(entry_card_id,entry_name,entry_unit,entry_type))

    button_constructe.grid(row=4)

    def addcard(en1,en2,en3,en4):

    cardid=en1.get()

    name=en2.get()

    unit=en3.get()

    c_type=en4.get()

    select="select card_id from lib_card where card_id="{}"".format(cardid)

    if (c_type not in ("T","S","O")):

    showinfo("error","NO SUCH TYPE")

    return 0

    line=LIB.select(select)

    if (len(line)!=0):

    showinfo("addition failure","Already have this ID!")

    else:

    insert="insert into lib_card values("{}","{}","{}","{}")".format(cardid,name,unit,c_type)

    LIB.insert(insert)

    showinfo("ok","addition success")

    return 1

    #insert book

    def inbook():

    insert_book=Toplevel(root)

    insert_book.title("insert book")

    text_insert=Text(insert_book)

    text_insert.pack()

    button_confirm=Button(insert_book,text="confirm")

    button_confirm.bind("",lambda x:booksin(text_insert))

    button_confirm.pack()

    def booksin(text_insert):

    string=text_insert.get("0.0",END)

    string=string.split(" ")

    print(string)

    for line in string:

    if line=="":

    break

    lines=line.split(",")

    bookid=lines[0][1:]

    t=lines[1]

    name=lines[2]

    publisher=lines[3]

    year=lines[4]

    writer=lines[5]

    price=lines[6]

    total=lines[7]

    stock=lines[8][:-1]

    if (int(stock)>int(total) or int(price)<0):

    showinfo("insert error!","stock wrong or price is below 0!")

    continue

    #print("insert into book values("{}","{}","{}","{}",{},"{}",{},{},{})".format(bookid,t,name,publisher,year,writer,price,total,stock))

    t=LIB.insert("insert into book values("{}","{}","{}","{}",{},"{}",{},{},{})".format(bookid,t,name,publisher,year,writer,price,total,stock))

    if (t==0):

    showinfo("error","book {} has been inserted".format(bookid))

    showinfo("success","insert has been done")

    #original window

    label_type=Label(root,text="TYPE").grid(row=3,sticky=W,column=0)

    label_name=Label(root,text="NAME").grid(row=3,sticky=W,column=1)

    label_year=Label(root,text="YEAR(XXXX-XXXX)").grid(row=3,sticky=W,column=2)

    label_publisher=Label(root,text="PUBLISHER").grid(row=3,sticky=W,column=3)

    label_writer=Label(root,text="WRITER").grid(row=3,sticky=W,column=4)

    label_lowprice=Label(root,text="lowestprice").grid(row=3,sticky=W,column=5)

    label_highprice=Label(root,text="highestprice").grid(row=3,sticky=W,column=6)

    label_order=Label(root,text="order by").grid(row=0,sticky=W,column=6)

    entry_type=Entry(root)

    entry_type.grid(row=4,column=0,sticky=W)

    entry_name=Entry(root)

    entry_name.grid(row=4,column=1,sticky=W)

    entry_year=Entry(root)

    entry_year.grid(row=4,column=2,sticky=W)

    entry_publisher=Entry(root)

    entry_publisher.grid(row=4,column=3,sticky=W)

    entry_writer=Entry(root)

    entry_writer.grid(row=4,column=4,sticky=W)

    entry_price1=Entry(root)

    entry_price1.grid(row=4,column=5,sticky=W)

    entry_price2=Entry(root)

    entry_price2.grid(row=4,column=6,sticky=W)

    #order the result

    order_index=0

    Lb_order=Listbox(root,selectmode=SINGLE,height=6)

    order="name","book_type","T","writer","price","publisher"

    Lb_order.insert(0,order[0])

    Lb_order.insert(1,"type")

    Lb_order.insert(2,"year")

    Lb_order.insert(3,order[3])

    Lb_order.insert(4,order[4])

    Lb_order.insert(5,order[5])

    Lb_order.grid(row=0,column=7,sticky=W)

    Lb_order.selection_set(0)

    def booksearch():

    select="select BookID,book_type,name,publisher,T,writer,price,total,stock from book"

    order_index=Lb_order.curselection()

    if (len(order_index)!=0):

    order_index=order_index[0]

    else:

    order_index=0;

    orders=order[order_index]

    name=entry_name.get()

    book_type=entry_type.get()

    publisher=entry_publisher.get()

    year=entry_year.get()

    writer=entry_writer.get()

    price1=entry_price1.get()

    price2=entry_price2.get()

    year1=year[0:4]

    year2=year[5:9]

    count=0

    if name!="":

    if count!=0:

    select+=" and"

    else:select+=" where"

    count+=1

    select+=" name="{}"".format(name)

    if book_type!="":

    if count!=0:

    select+=" and"

    else:select+=" where"

    count+=1

    select+=" book_type="{}"".format(book_type)

    if publisher!="":

    if count!=0:

    select+=" and"

    else:select+=" where"

    count+=1

    select+=" publisher="{}"".format(publisher)

    if year1!="":

    if year2=="":

    if count!=0:

    select+=" and"

    else:select+=" where"

    count+=1

    select+=" t={}".format(year1)

    else:

    if count!=0:

    select+=" and"

    else:select+=" where"

    count+=1

    select+=" T between {} and {}".format(year1,year2)

    if writer!="":

    if count!=0:

    select+=" and"

    else:select+=" where"

    count+=1

    select+=" writer="{}"".format(writer)

    if price1!="":

    if price2!="":

    if count!=0:

    select+=" and"

    else:select+=" where"

    count+=1

    select+=" price between {} and {}".format(price1,price2)

    else:

    if count!=0:

    selece+="and"

    else:select+=" where"

    count+=1

    select+=" price={}".format(price1)

    if orders=="":

    select+=" order by name"

    else:

    select+=" order by {}".format(orders)

    print(select)

    curs=LIB.select(select)

    searchresult=Toplevel(root)

    searchresult.title("result")

    text=Text(searchresult)

    text.insert(INSERT,"BookID type name publish year writer price total stock ")

    for (BookIDs,book_types,names,publishers,years,writers,prices,totals,stocks) in curs:

    text.insert(INSERT,"{} {} {} {} {} {} {} {} {} ".format(BookIDs,book_types,names,publishers,years,writers,prices,totals,stocks))

    text.pack()

    def display_rent(en_cardid):

    cardid=en_cardid.get()

    select="select card_id from lib_card where card_id="{}"".format(cardid)

    curs=LIB.select(select)

    order_index=Lb_order.curselection()

    if len(order_index)!=0 :

    order_index=order_index[0]

    else:

    order_index=0;

    orders=order[order_index]

    if ((cardid,) in curs):

    select="select card_id,name,unit,c_type from lib_card where card_id="{}"".format(cardid)

    curs=LIB.select(select)

    top=Toplevel(root)

    text=Text(top)

    for (card_id,name,unit,c_type) in curs:

    text.insert(INSERT,"card_id:{} ".format(card_id))

    text.insert(INSERT,"name:{} ".format(name))

    text.insert(INSERT,"unit:{} ".format(unit))

    text.insert(INSERT,"c_type:{} ".format(c_type))

    select="select BookID,book_type,name,publisher,t,writer,price,total,stock from book natural join record where card_id="{}" and still=1 order by {}".format(cardid,orders)

    curs=LIB.select(select)

    text.insert(INSERT,"BookID type name publish year writer price total stock ")

    for (BookID,book_type,name,publisher,t,writer,price,total,stock) in curs:

    text.insert(INSERT,"{} {} {} {} {} {} {} {} {} ".format(BookID,book_type,name,publisher,t,writer,price,total,stock))

    text.pack()

    else:

    showinfo("Error","NO SUCH CARD")

    def checkcard(cardid):

    select="select card_id from lib_card where card_id="{}"".format(cardid)

    curs=LIB.select(select)

    if (cardid,) in curs:

    return 1

    else:

    return 0

    def rent(BookID,cardid,brokerage):

    if not (checkcard(cardid)):

    showinfo("error","no such card")

    return 0

    select="select stock from book where BookID="{}"".format(BookID)

    stocks=LIB.select(select)

    #stocks=curs.fetchall()

    stock=stocks[0]

    if (stock>(0,)):

    update="update book set stock=stock-1 where BookID="{}"".format(BookID)

    flag=LIB.update(update)

    if flag:

    insert="insert into record values("","{}","{}",CURDATE(),DATE_ADD(CURDATE(),INTERVAL 1 MONTH),"{}",1)".format(cardid,BookID,brokerage)

    LIB.insert(insert)

    showinfo("rent success","OK")

    else:

    showinfo("rent failure","stock wrong")

    else:

    select="select return_time from record where BookID="{}" and return_time>=all(select return_time from record where BookID="{}")".format(BookID,BookID)

    date=LIB.select(select)

    #date=curs.fetchall()

    date=str (date)

    showinfo("Out of stock","There are no more such book,The recent returning will be at:{}-{}-{}".format(date[16:20],date[22:23],date[26:27]))

    return 1

    def back(BookID,cardid):

    if not(checkcard(cardid)): return 0

    select="select BookID from record where BookID="{}" and card_id="{}" and still=1".format(BookID,cardid)

    curs=LIB.select(select)

    if (BookID,) in curs:

    select="select record_id from record where BookID="{}" and card_id="{}" and still=1 order by rent_time".format(BookID,cardid)

    cur=LIB.select(select)

    #cur=curss.fetchall()

    for record in cur:

    recordid=str (record)

    recordid=recordid[1:]

    recordid=recordid[:-2]

    update="update record set still=0 where record_id="{}"".format(recordid)

    LIB.update(update)

    update="update book set stock=stock+1 where BookID="{}"".format(BookID)

    LIB.update(update)

    break

    showinfo("message","Return Success!")

    return 1

    else:

    showinfo("error","You can"t return the book!")

    return 1

    def deletecard(card):

    cardid=card.get()

    if not (checkcard(cardid)):

    showinfo("error","NO SUCH CARD")

    return 0

    select="select record_id from record where card_id="{}" and still=1".format(cardid)

    curs=LIB.select(select)

    for record_id in curs:

    showinfo("error","Some books this card rented haven"t been returned")

    return 0

    delete="delete from lib_card where card_id="{}"".format(cardid)

    LIB.delete(delete)

    showinfo("ok","success")

    return 1

    label_id=Label(root,text="ID: ")

    label_id.grid(row=0,sticky=W)

    ide=Entry(root)

    ide.grid(row=0,column=1,sticky=E)

    label_psw=Label(root,text="PassWord: ").grid(row=1,sticky=W)

    pwde=Entry(root,show="*")

    pwde.grid(row=1,column=1,sticky=E)

    log_button=Button(root,text="Login",command=login)

    log_button.grid(row=2,column=1)

    button_search=Button(root,text="Search Book",command=booksearch)

    button_search.grid(row=4,column=7,sticky=W)

    print("all done")

    root.mainloop()

    更多学习资料请关注专题《管理系统开发》。

    以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

    展开全文
  • 题目:写一个简单的图书...学校二手书是个大市场,A老师决定涉足这个领域,她需要写一个图书管理系统帮她管理书籍的借阅情况,她希望这个程序可以做到:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭...

    题目:写一个简单的图书借阅系统‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    学校二手书是个大市场,A老师决定涉足这个领域,她需要写一个图书管理系统帮她管理书籍的借阅情况,她希望这个程序可以做到:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    1. 查询书籍:可以一键查询系统里所有书籍的信息和借阅情况‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬
    2. 添加书籍:往系统添加书籍时,需要输入书籍的基本信息(书名,作者,推荐理由)‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬
    3. 借阅书籍:当书籍的状态是“未借出”的时候,书籍才可以借,借出以后的书籍状态为“已借出”‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬
    4. 归还书籍:归还成功后书籍的状态会更改成“未借出”,下一个同学可以再借了。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    既然已经学习了类和对象,所以不用考虑其他编程模式。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    类的两种用法:1. 类作为实例对象的模板 2. 类作为函数包。第一种用法是使用类生成实例对象。类作为实例对象的模版,每个实例创建后,都将拥有类的所有属性和方法。第二种用法是用类将多个函数(方法)打包封装在一起,让类中的方法相互配合。‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    该项目中,处理的对象是每本具体的书籍,每本书都有自己的属性信息,由此,可以定义一个Book类,利用Book类创建一个个书的实例,绑定属性(第一种用法)‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    而对于而这个管理系统的运行主体,是多个可供选择的功能的叠加,所以我们可以创建一个系统运行类BookManager,将查询书籍、添加书籍等功能封装成类中的方法以供调用(第二种用法)‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    课堂上,我们已编写了基本功能,见附件1BookRent.py‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    ------------------------------------------‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    对程序进行改造升级:‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬

    1. 图书信息从CSV文件获取(附件2),注意在借阅和归还时修改图书的状态‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬
    2. 考虑对书籍进行分类:继承Book类,创建一些子类,例如,FictionBook,改造其初始化方法,增加参数type=‘玄幻类’‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‭‬‫‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‭‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‪‬‪‬‪‬‪‬‪‬‪‬‮‬‪‬‫‬
    3. 实现模糊查询:例如,让用户输入作者名,就能打印出系统里该作者所有书籍的相关信息;输入玄幻类,打印出所有这类书籍的相关信息

    CSV表格部分如下:
    在这里插入图片描述

    代码:

    # coding = utf-8
    import csv
    from itertools import islice
    import pandas as pd
    import os
    
    
    class Book:
        def __init__(self, name, author, recommendation, type, status=0):  # 对实例属性进行初始化
            self.name = name
            self.author = author
            self.recommendation = recommendation
            self.status = status
            self.type = type
    
        def __str__(self):
            if self.status == 1:
                status = '已借出'
            else:
                status = '未借出'
            return '名称:《%s》作者:%s 推荐语:%s 类别: %s 状态:%s ' % (self.name, self.author, self.recommendation, self.type, status)
    
    
    class FictionBook(Book):
        def __init__(self, type='奇幻'):
            self.type = type
    
    
    class NovelBook(Book):
        def __init__(self, type='小说'):
            self.type = type
    
    
    class JottingsBook(Book):
        def __init__(self, type='随笔'):
            self.type = type
    
    
    class BookManager:
        books = []
    
        def __init__(self):
            f = open('BookInfos.csv', 'r')
            readers = csv.reader(f)
            for row in islice(readers, 1, None):
                self.books.append(Book(row[0], row[1], row[2], row[3], row[4]))
            f.close()
    
        def menu(self):  # 显示选择菜单,根据不同菜单的选项调用不同的方法
            print('欢迎使用大数据团队图书节约系统,每本书都是好书,希望钟老师的市场越来越好。\n')
            while True:
                print(' 1.查询书籍\n 2.添加书籍\n 3.借阅书籍\n 4.归还书籍\n 5.退出系统\n')
                choice = int(input('请输入数字选项对应的功能,例如:1(指....)'))
                if choice == 1:
                    self.show_all_book()
                elif choice == 2:
                    self.add_book()
                elif choice == 3:
                    self.lend_book()
                elif choice == 4:
                    self.return_book()
                elif choice == 5:
                    print('感谢使用!欢迎下次再来!')
                    break
    
        def show_all_book(self):  # 显示书籍信息
            print("1.查询作者相关书籍\n2.查询类别相关书籍\n3.查询所有书籍")
            ch = eval(input('请输入你的选择:例如:1(指....)'))
            if ch == 1:
                author = input("请输入作者名字:")
                for book in self.books:
                    if book.author == author:
                        print('')
                        print(book)
            elif ch == 2:
                type = input("请输入书籍类别:")
                for book in self.books:
                    if book.type == type:
                        print('')
                        print(book)
            elif ch == 3:
                for book in self.books:
                    print('')
                    print(book)
            else:
                print("您的输入有误噢!")
    
        def add_book(self):  # 添加书籍
            new_name = input('请输入书籍的名字:')
            new_author = input('请输入书籍的作者:')
            new_comment = input('请输入书籍的推荐语:')
            new_type = input('请输入书籍的类别:')
            new_book = [new_name, new_author, new_comment, new_type, 0]
            # 写入CSV文件
            f = open('BookInfos.csv', 'a+')
            writer = csv.writer(f)
            writer.writerow(new_book)
            f.close()
            # 改变books[]
            self.books.append(Book(new_book[0], new_book[1], new_book[2], new_book[3], new_book[4]))
            print('书籍录入成功!\n')
    
        def check_book(self, name):  # 检查是否存在该书籍
            for book in self.books:
                if book.name == name:
                    return book
            else:
                return -1
    
        def lend_book(self):  # 借阅书籍
            name = input('请输入你想借阅的书籍名字:')
            res = self.check_book(name)
            if res != -1:
                if res.status == 1:
                    print('你来晚了,这本书已经被借走了')
                else:
                    print('借阅成功!借了不看会变胖~~~')
                    res.status = 1
                    manager.change_status(name)
            else:
                print('这本书暂时没有在系统里!')
    
        def return_book(self):  # 归还书籍
            name = input('请输入归还书籍的名字:')
            res = self.check_book(name)
            if res == -1:
                print('没有这本书,你恐怕输错书名了~')
            else:
                if res.status == 0:
                    print('这本书没有被借走!')
                else:
                    print('归还成功')
                    res.status = 0
                    manager.change_status(name)
                    # 这里我做实验时有些些问题,去掉manager.会出现 name is not defined 学艺不精,还不够了解python,见谅
    
        @staticmethod
        def change_status(name):  # 修改CSV文件中借还书籍的状态
            in_file = open("BookInfos.csv", "r")
            reader = csv.reader(in_file)
            out_file = open("BookInfos1.csv", "w", newline='')
            writer = csv.writer(out_file)
            for row in reader:
                if row[0] == name:
    
                    if row[4] == '0':
                        row[4] = '1'
                    else:
                        row[4] = '0'
                writer.writerow(row)
            in_file.close()
            out_file.close()
            os.remove("BookInfos.csv")  # 删除原文件
            os.rename("BookInfos1.csv", "BookInfos.csv")  # 重命名写入文件,此法不可取,但是我暂时找不到好的方法了
            print("已修改CSV文件")
            # 这里我做实验时也有些些问题。1.不会修改特定单元格,2.选择了修改后替换原文件的方法,此法若真实用于大型文件管理,会导致效率大幅度降低,不可取,见谅
    
    
    manager = BookManager()
    manager.menu()
    
    

    此次实验前前后后断断续续做了5天左右,主要还是对python的CSV模块不太熟悉,建议大家好好学习哈哈哈哈(流下了不学无术的泪…)

    展开全文
  • 基于python图书管理系统代码,对于需要完成图书管理系统作业的同学来说是一个福利哦,欢迎大家欣赏。~~~
  • Python实现图书管理系统

    万次阅读 2019-06-26 09:44:05
    Python实现图书管理系统 功能描述 1.界面分为两个部分,分别是(1)登录注册界面(2)图书管理系统界面 2.用户名和密码提前存储在列表中,输入用户名或密码错误提示重新输入,未注册的需要先注册帐号密码,再...
  • 人生苦短,我用Python,咱们今天就来分享一个用Python语言开发的基于Django框架的图书管理系统吧。项目前台和后台界面模板都是自己编写,前台采用Bootstrap框架UI,后台EasyUI框架UI,没有采用Django自动生成的那个...
  • 本文实例为大家分享了python图书管理系统的具体代码,供大家参考,具体内容如下 图书管理系统 import random # books={书名:剩余数量, 书名:剩余数量} import time books = {防脱发指南: 5, 颈椎康复指南: 3, 从...
  • python实现一个简单的图书管理系统 ,供大家参考,具体内容如下 1、工具:PyCharm3.6 社区版 我创建了一个工程叫fairy,把解释器换成Pytnon3.6 创建一个pytnon file:图书管理系统.py 2、实现简单界面如下: ...
  • classBms(models.Model): pid= models.AutoField(primary_key=True)#更改默认id的名字 name = models.CharField(max_length=20,unique=True) #varcher(20) 在Termial中执行命名,迁移数据库 python manage.py ...
  • [python]代码库'''2.16 作业定义类,图书特征:XXXXX...行为:打印信息编写一段代码让用户通过控制台,输入图书的各种信息,由此创建图书对象将图书对象保存到一个集合中()可以查询集合中所有的图书信息可以通过图书...
  • 开发语言:Python | 大小:19.05M | 发布时间:2019-05-27 | 发布人:李易峰相关标签:立即下载开发语言:Python | 大小:0.21M | 发布时间:2020-08-23 | 发布人:聂嘉辉相关标签:立即下载开发语言:Python | 大小...
  • 内容简介:这篇文章主要为大家详细介绍了python实现图书管理系统,具有一定的参考价值,感兴趣的小伙伴们可以参考一下本文实例为大家分享了 python 实现图书管理系统的具体代码,供大家参考,具体内容如下import ...
  • 首先展示一下图书管理系统的首页:这是图书管理系统的发布图书页面:最后是图书管理系统的图书详情页已经图书进行删除的管理页。该图书管理系统为练习阶段所做,能够实现图书详情的查询、图书的添加、图书的删除功能...
  • python实实现现简简单单图图书书管管理理系系统统 这篇文章主要为大家详细介绍了python实现简单图书管理系统文中示例代码介绍的非常详细具有一定的参考 价值感兴趣的小伙 们可以参考一下 用python实现一个简单的图书...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 12,353
精华内容 4,941
关键字:

python图书管理系统代码

python 订阅