欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

基于python實(shí)現(xiàn)圖書(shū)管理系統(tǒng)

 更新時(shí)間:2021年04月16日 08:42:22   作者:昇柱  
這篇文章主要為大家詳細(xì)介紹了基于python實(shí)現(xiàn)圖書(shū)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python實(shí)現(xiàn)圖書(shū)管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

添加新書(shū)

查詢

借閱

二次添加新書(shū)(讀取已有的.xls并修改)

代碼:

import xlwt
import xlrd


def read_old_data(row0_len):
    try:
        filename=".\圖書(shū).xls"
        old_data = []#讀取表格已有內(nèi)容
        data = xlrd.open_workbook(filename)
        sheet0 = data.sheet_by_index(0)
        nrows = sheet0.nrows  #獲取該sheet中的有效行數(shù)
        print("Info:讀取到已有數(shù)據(jù)表格")
        print("有效行數(shù):",nrows)
        for i in range(nrows):
            for j in range(row0_len):
                old_data.append(sheet0.cell(i,j).value)
        print("共有舊的數(shù)據(jù):",len(old_data))
    except IOError:
        print("Info: 沒(méi)有找到文件或讀取文件失敗/n1 =>新建圖書(shū).xls文件")
        nrows=0
    return old_data,nrows

def new_book():

    book = []
    print_value=("書(shū)名","作者","編號(hào)","位置","數(shù)量")
    row0_len=len(print_value)#列數(shù)
    input_value=''
    '''
    try:

    '''
    (old_data,nrows)=read_old_data(row0_len)
    
    #打開(kāi)存儲(chǔ)
    book_excel = xlwt.Workbook()
    sheet1 = book_excel.add_sheet("books",cell_overwrite_ok=0)

    #寫(xiě)入舊數(shù)據(jù):
    for i in range(nrows):
        for j in range(row0_len):
            sheet1.write(i,j,old_data[(i*row0_len)+j])

    while(1):
        print("添加新書(shū)")
        #輸入
        for i in range(row0_len):
            print("請(qǐng)輸入:"+print_value[i])
            input_value = input()

            #判斷是否輸出
            if(input_value == 'q'):
                book_excel.save("圖書(shū).xls")
                return
            book.append(input_value)
        #保存到硬盤(pán)
        for i in range(row0_len):
            sheet1.write(nrows,i,book[i])
        nrows=nrows+1
        book=[]#清空book緩存
    return


def search():
    #打開(kāi)excel
    book_excel = xlrd.open_workbook("圖書(shū).xls")
    sheet1 = book_excel.sheets()[0]
    book_num =sheet1.nrows
    #while(1):
    #輸入書(shū)名
    bookname = input("請(qǐng)輸入書(shū)名:")
    find_flag=0
    #查找
    for i in range(book_num):
        if(bookname == sheet1.cell_value(i,0)):
            if(int(sheet1.cell_value(i,4))>0):
                find_flag=1
                print("書(shū)名:",sheet1.cell_value(i,0))
                print("作者:",sheet1.cell_value(i,1))
                print("位置:",sheet1.cell_value(i,3))
                print("庫(kù)存(本):",sheet1.cell_value(i,4))
                return
    if(find_flag==1):
        print("查無(wú)此書(shū)。")
    return

def borrow():
    #打開(kāi)excel
    book_excel =xlrd.open_workbook("圖書(shū).xls")
    sheet1 = book_excel.sheets()[0]
    book_num = sheet1.nrows
    row0_len=5#5列
    while(1):
        #輸入書(shū)名
        bookname = input("請(qǐng)輸入書(shū)名:")
        if(bookname == 'q'):
            return
        #查找
        for i in range(0,book_num):
            if(bookname == sheet1.cell(i,0).value):

                kucun=int(sheet1.cell_value(i,4))
                
                if(kucun>0):
                    (old_data,nrows)=read_old_data(row0_len)#5列
                    book_excel_w = xlwt.Workbook("圖書(shū).xls")
                    sheet2 = book_excel_w.add_sheet("books",cell_overwrite_ok=True)
                    #寫(xiě)入舊數(shù)據(jù):
                    for n in range(nrows):
                        for j in range(row0_len):
                            sheet2.write(n,j,old_data[(n*row0_len)+j])
                    
                    print("借到了!")
                    sheet2.write(i,4,str(kucun-1))
                    print("剩余庫(kù)存:",kucun-1)
                    book_excel_w.save("圖書(shū).xls")
                    break
    return


def main_window():
    while(1):
        print("\n====圖書(shū)管理系統(tǒng)====")
        print("1.新書(shū)加入")
        print("2.書(shū)籍查詢")
        print("3.圖書(shū)借閱")
        print("========4退出=======")
        x= (input("請(qǐng)輸入你的操作"))
        print('\n')
        if(x == '1'):
            new_book()
        elif(x=='2'):
            search()
        elif(x=='3'):
            borrow()
            
        elif(x=='4'):
            break
        else:
            print("輸入無(wú)效")

    return


main_window()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解python metaclass(元類(lèi))

    詳解python metaclass(元類(lèi))

    這篇文章主要介紹了python metaclass(元類(lèi))的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • python去除空格和換行符的實(shí)現(xiàn)方法(推薦)

    python去除空格和換行符的實(shí)現(xiàn)方法(推薦)

    下面小編就為大家?guī)?lái)一篇python去除空格和換行符的實(shí)現(xiàn)方法(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-01-01
  • Python變量和字符串詳解

    Python變量和字符串詳解

    本篇文章主要介紹了Python變量和字符串的相關(guān)資料。具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧
    2017-04-04
  • Python word2vec訓(xùn)練詞向量實(shí)例分析講解

    Python word2vec訓(xùn)練詞向量實(shí)例分析講解

    這篇文章主要介紹了Python word2vec訓(xùn)練詞向量實(shí)例分析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧
    2022-12-12
  • django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式

    django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式

    這篇文章主要介紹了django創(chuàng)建超級(jí)用戶時(shí)指定添加其它字段方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-05-05
  • Python數(shù)據(jù)結(jié)構(gòu)與算法中的隊(duì)列詳解(1)

    Python數(shù)據(jù)結(jié)構(gòu)與算法中的隊(duì)列詳解(1)

    這篇文章主要為大家詳細(xì)介紹了Python的隊(duì)列,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2022-03-03
  • 對(duì)于Python中線程問(wèn)題的簡(jiǎn)單講解

    對(duì)于Python中線程問(wèn)題的簡(jiǎn)單講解

    這篇文章主要介紹了對(duì)于Python中線程問(wèn)題的簡(jiǎn)單講解,線程一直是Python編程當(dāng)中的熱點(diǎn)問(wèn)題,而本文沒(méi)有涉及GIL線程鎖方面的內(nèi)容,需要的朋友可以參考下
    2015-04-04
  • python flask 如何修改默認(rèn)端口號(hào)的方法步驟

    python flask 如何修改默認(rèn)端口號(hào)的方法步驟

    這篇文章主要介紹了python flask 如何修改默認(rèn)端口號(hào)的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-07-07
  • Jupyter Notebook折疊輸出的內(nèi)容實(shí)例

    Jupyter Notebook折疊輸出的內(nèi)容實(shí)例

    這篇文章主要介紹了Jupyter Notebook折疊輸出的內(nèi)容實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-04-04
  • python中enumerate函數(shù)用法實(shí)例分析

    python中enumerate函數(shù)用法實(shí)例分析

    這篇文章主要介紹了python中enumerate函數(shù)用法,以實(shí)例形式較為詳細(xì)的分析了enumerate函數(shù)的功能、定義及使用技巧,需要的朋友可以參考下
    2015-05-05

最新評(píng)論