2021-09-30 密码版 物资管理系统

from os import system
from sys import exit
from random import randint
from time import sleep

user={'root':'88888888'}
error_time=4
mode=False
chack=[None,None]
user_name=''
user_passwd=[None,None]

#读取用户
try:
	f=open('user.txt','r')
	user=eval(f.read())
	f.close()
except:
	f=open('user.txt','w')
	f.write("{'root':'88888888'}")
	f.close
	user={'root':'88888888'}

#main
while True:
	user_name=str(input('请输入用户名>'))
	#判断用户是否存在

	if user_name not in user:#用户不存在 -> 注册 -> 设置用户名
		print('用户不存在,将执行注册操作。')
		if ' ' in user_name:
			print('\aErr: 用户名中不能有空格')
		elif user_name=='':
			print('\aErr: 用户名不能为空')
		else:
			#设置密码
			while True:
				user_passwd[0]=str(input('请设置密码>'))
				if ' ' in str(user_passwd[0]):
					print('\aErr: 密码中不能含有空格。')
				elif user_passwd[0]=='':
					print('\aErr: 密码不能为空。')
				elif len(user_passwd[0])<6:
					print('\aErr: 密码长度太短,至少6位。')
				else:
					#再次输入密码
					user_passwd[1]=str(input('请再次输入密码>'))
					if user_passwd[0]!=user_passwd[1]:
						print('\aErr: 两次输入的密码不一致。')
					else:
						print('注册成功!\n\n请重新登录:')
						user[user_name]=user_passwd[0]
						#写入文件
						f=open('user.txt','w')
						f.write(str(user))
						f.close()
						break

	else:    #用户存在 -> 登录 -> 确认密码是否正确
		#错4次后验证码确认
		while error_time!=0:
			user_passwd[0]=input('请输入密码 4/'+str(error_time)+'>')
			if user_passwd[0]!=user[user_name]:
				print('\aErr: 密码错误')
				error_time=error_time-1
			else:
				mode=True
				break
		else:
			print("请重式")

        

	if mode==True:
		break

input('登录成功...')



borrower=user_name
class Thing:
 
    def __init__(self, sname, name,detaction ,borrower=0,state = 0):
        self.sname = sname
        self.name = name
        self.detaction = detaction
        self.state = state
        self.borrower=borrower
 
    def __str__(self):
        status = '未借出'
        if self.state == 1:
            status = '已借出'
        return '缩写:(%s) 全称:%s  描述:%s\n状态:%s 借出人:%s' % (self.sname, self.name, self.detaction,status,self.borrower)
 
class ThingManager:

    things = []
    def __init__(self):
        thing1 = Thing('jsq','计算器','卡西欧',)
        self.things.append(thing1)
        
 
    def menu(self):
        print('欢迎使用物资管理系统\n')
        while True:
            print('1.查询所有物资\n2.添加物资\n3.借物资\n4.归还物资\n5.退出系统\n')
            choice = int(input('请输入数字选择对应的功能:'))
            if choice == 1:
                self.show_all_thing()
            elif choice == 2:
                self.add_thing()
            elif choice == 3:
                self.lend_thing()
            elif choice == 4:
                self.return_thing()
            else:
                print('感谢使用!')
                break
 
    def show_all_thing(self):
        print('物资信息如下:')
        for thing in self.things:
            print(thing)
            print('')

    def add_thing(self):
        new_sname = input('请输入物资缩写:')
        new_name =  input('请输入全称:')
        new_detaction = input('请输入物资描述:')
        
        new_thing = Thing(new_sname, new_name, new_detaction)
        self.things.append(new_thing)
        print('物资录入成功!\n')

    def check_thing(self,sname):
        for thing in self.things:
            if thing.sname == sname:
                 return thing 
        else:
            return None

    def lend_thing(self):
        sname = input('请输入物资的缩写:')
        res = self.check_thing(sname)

        if res != None:
            if res.state == 1:
                print('已经被%s借走 '%(borrower))
            else:
                print('成功')
                res.state = 1
                res.borrower = user_name
        else:
            print('物资暂时没有收录在系统里')
    
    def return_thing(self):
        sname = input('请输入归还物资的缩写:')
        res = self.check_thing(sname)
        if res == None:
            print('没有该物资')
        else:
            if res.state == 0:
                print('物资没有被借走')
            else:
                print('归还成功!')
                res.state = 0
                res.borrower=0
 
manager = ThingManager()
manager.menu()

这次加入了密码验证系统(生产密码储存文件)

借出人管理系统(但因为今天有课,所以没有加入导入导出物资档案功能)

猜你喜欢

转载自blog.csdn.net/secret125/article/details/120573718
今日推荐