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

查詢


借閱


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


代碼:
import xlwt
import xlrd
def read_old_data(row0_len):
try:
filename=".\圖書.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: 沒有找到文件或讀取文件失敗/n1 =>新建圖書.xls文件")
nrows=0
return old_data,nrows
def new_book():
book = []
print_value=("書名","作者","編號","位置","數(shù)量")
row0_len=len(print_value)#列數(shù)
input_value=''
'''
try:
'''
(old_data,nrows)=read_old_data(row0_len)
#打開存儲
book_excel = xlwt.Workbook()
sheet1 = book_excel.add_sheet("books",cell_overwrite_ok=0)
#寫入舊數(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("添加新書")
#輸入
for i in range(row0_len):
print("請輸入:"+print_value[i])
input_value = input()
#判斷是否輸出
if(input_value == 'q'):
book_excel.save("圖書.xls")
return
book.append(input_value)
#保存到硬盤
for i in range(row0_len):
sheet1.write(nrows,i,book[i])
nrows=nrows+1
book=[]#清空book緩存
return
def search():
#打開excel
book_excel = xlrd.open_workbook("圖書.xls")
sheet1 = book_excel.sheets()[0]
book_num =sheet1.nrows
#while(1):
#輸入書名
bookname = input("請輸入書名:")
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("書名:",sheet1.cell_value(i,0))
print("作者:",sheet1.cell_value(i,1))
print("位置:",sheet1.cell_value(i,3))
print("庫存(本):",sheet1.cell_value(i,4))
return
if(find_flag==1):
print("查無此書。")
return
def borrow():
#打開excel
book_excel =xlrd.open_workbook("圖書.xls")
sheet1 = book_excel.sheets()[0]
book_num = sheet1.nrows
row0_len=5#5列
while(1):
#輸入書名
bookname = input("請輸入書名:")
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("圖書.xls")
sheet2 = book_excel_w.add_sheet("books",cell_overwrite_ok=True)
#寫入舊數(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("剩余庫存:",kucun-1)
book_excel_w.save("圖書.xls")
break
return
def main_window():
while(1):
print("\n====圖書管理系統(tǒng)====")
print("1.新書加入")
print("2.書籍查詢")
print("3.圖書借閱")
print("========4退出=======")
x= (input("請輸入你的操作"))
print('\n')
if(x == '1'):
new_book()
elif(x=='2'):
search()
elif(x=='3'):
borrow()
elif(x=='4'):
break
else:
print("輸入無效")
return
main_window()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python實(shí)現(xiàn)簡易圖書管理系統(tǒng)
- python編寫圖書管理系統(tǒng)
- Python實(shí)現(xiàn)簡易的圖書管理系統(tǒng)
- Python實(shí)現(xiàn)圖書借閱管理系統(tǒng)
- Python實(shí)現(xiàn)圖書管理系統(tǒng)設(shè)計(jì)
- python代碼實(shí)現(xiàn)圖書管理系統(tǒng)
- python實(shí)現(xiàn)簡單圖書管理系統(tǒng)
- Python簡易版圖書管理系統(tǒng)
- python面向?qū)ο蠓▽?shí)現(xiàn)圖書管理系統(tǒng)
- wxpython實(shí)現(xiàn)圖書管理系統(tǒng)
- python圖書管理系統(tǒng)
- python實(shí)現(xiàn)圖書管理系統(tǒng)
- python模擬實(shí)現(xiàn)圖書管理系統(tǒng)
相關(guān)文章
python實(shí)現(xiàn)的AES雙向?qū)ΨQ加密解密與用法分析
這篇文章主要介紹了python實(shí)現(xiàn)的AES雙向?qū)ΨQ加密解密與用法,簡單分析了AES加密解密算法的基本概念并結(jié)合實(shí)例形式給出了AES加密解密算法的相關(guān)實(shí)現(xiàn)技巧與使用注意事項(xiàng),需要的朋友可以參考下2017-05-05
python 實(shí)現(xiàn)分組求和與分組累加求和代碼
這篇文章主要介紹了python 實(shí)現(xiàn)分組求和與分組累加求和代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05
Python語法學(xué)習(xí)之進(jìn)程池與進(jìn)程鎖詳解
這篇文章主要為大家介紹了Python進(jìn)程中兩個重要的知識點(diǎn):進(jìn)程池與進(jìn)程鎖,文中通過示例詳細(xì)為大家講解了二者的使用,感興趣的可以了解下2022-04-04
Android Q之氣泡彈窗的實(shí)現(xiàn)示例
這篇文章主要介紹了Android Q之氣泡彈窗的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06
一文了解Python并發(fā)編程的工程實(shí)現(xiàn)方法
這篇文章主要介紹了Python并發(fā)編程的工程實(shí)現(xiàn),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05
ubuntu安裝sublime3并配置python3環(huán)境的方法
這篇文章主要介紹了ubuntu安裝sublime3并配置python3環(huán)境的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03

