Python实现图书管理系统

本人的这款软件曾在全市电脑制作活动中荣获二等奖,现在本人公开其代码,供大家参考。

# coding=gbk

import json

import os


import datetime
def mytest():
	my_dict={'x':4,'y':5}
	print(my_dict['x'])
	print(my_dict['z'])
#mytest()


print('个人图书管理系统 v1.2.0')

print('开发者:韩邦泽')
print('E-mail:hbz619@126.com')

if os.access("info.json",os.F_OK):
	
	#print('file exists')
	pass
else:
	#print("file not exist")
	#exit()
	
	
	with open('info.json','w') as j:
		y={}	
		j.write("{}")
		j.flush()

if os.access('credit.json',os.F_OK):
	#print('credit.json exists')
	pass
else:
	#print('credit.json not exist')
	with open('credit.json','w')as k:
		k.write('{}')
		k.flush()



	

with open('credit.json','r') as credit_name:
		
	peoplecredit=json.load(credit_name)
with open('info.json','r') as book_info:
		
	y=json.load(book_info)




order=True
while order:
	year=datetime.datetime.now().year


	month=datetime.datetime.now().month

	want=input('您想办理什么业务,借书(B),还书(R),添加书(A),删除书(D),查询(F),黑名单(L),退出(E):')
	if want=='A' or want=='a':
		book_name=input('书名:')
		can_borrow=input('可借性(Y/N):')
		if can_borrow=='Y' or can_borrow=='N':
			whereis=input(' 图书位置:')
			#print(type(y))
			y[book_name]=[can_borrow,"",whereis,0,0]
			#print(y)
		else:
			print('对不起,您录入的可借性是非法的。')
		with open('info.json','w') as x:
			json.dump(y,x)
	if want=='E' or want=='e':
		order=False
		print('再见,谢谢使用!')
	if want=='D' or want=='d':
		books_name=input('书名:')
		del y[books_name]
		with open('info.json','w') as x:
			json.dump(y,x)
		print('图书已删除')
	if want=='B' or want=='b':
		name=input('借书者姓名:')
		borrowed_book=input('书名:')
		try:
			point1=peoplecredit[name]
			int(point1)
			
		except KeyError:
			peoplecredit[name]=10
			with open('credit.json','w') as f_obj:
				json.dump(peoplecredit,f_obj)
			point1=peoplecredit[name]	
		if point1!=0 or name not in peoplecredit:
			if y[borrowed_book][0]=='Y':
				y[borrowed_book][1]=name
				y[borrowed_book][3]=year
				y[borrowed_book][4]=month
				with open('info.json','w') as x:
					json.dump(y,x)
				
				
			
			else:
				print('对不起,图书不可借')
		else:
			print('对不起,您的信用积分为0.')
	if want=='R' or want=='r':
		borrowed_book_name=input('书名:')
		the_reader=y[borrowed_book_name][1]
		point=peoplecredit[the_reader]
		appointmamt_year=y[borrowed_book_name][3]
		appointmamt_month=y[borrowed_book_name][4]
		returned_month=appointmamt_month+1
		returned_year=appointmamt_year+1
		if appointmamt_month=='12':
			returned_year=appointmamt_year+1
			returned_month=1
			
		elif year>returned_year and month>returned_month or month>returned_month:
			point=point-1
			print('抱歉,读者,您的借书时间过长,您的信用积分会扣一分。')
			peoplecredit[the_reader]=point
			with open('credit.json','w') as z:
				json.dump(peoplecredit,z)
		y[borrowed_book_name][1]=''
		with open('info.json','w') as x:
			json.dump(y,x)
		print('图书已归还')
	if want=='F' or want=='f':
		want1=input('您想查询未还书者(P)还是书本位置(W)?')
		if want1=='P' or want1=='p':
			for persons,information in y.items():
				if information[1]!='':
					print(information[1],'未还',persons,'。')
		if want1=='W' or want1=='w':
			for book,information in y.items():
				print(book,'在',information[2])
	if want=='L' or want=='l':
		want_add_or_del=input('您想添加黑名单(A)还是删除黑名单(D)(注:删除黑名单后,被删者的信用积分会变为10.)')
		if want_add_or_del=='A' or want_add_or_del=='a':
			add_name=input('名字:')
			try:
				peoplecredit[add_name]=0
				with open('credit.json','w') as c:
					json.dump(peoplecredit,c)
			except KeyError:
				pass
		if want_add_or_del=='D' or want_add_or_del=='d':
			del_name=input('名字:')
			peoplecredit[del_name]=10
			with open('credit.json','w') as c:
				json.dump(peoplecredit,c)
			
os.system('pause')


			
		
		
		
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值