员工登录系统0.1

在列表中存存有一下数据

data_list = ['dream|521|music-run-sport',
'opp|666|swim-listen-sleep',
'hope_nb|888|eat-code',
'lj_bob_nb|000|read-write'
]

每一个元素对应的分别是

用户名|密码|爱好

获取每一个元素并 做登陆校验

校验用户是否存在,三次密码重试机会,校验密码是数字且必须是三位以内

密码正确登陆成功打印下列指定格式

欢迎用户 username 登陆!您有以下爱好 爱好1&爱好2&爱好3

如果用户名中带有 _nb 则打印 欢迎Vip用户 username 登陆!您有以下爱好 爱好1&爱好2&爱好3

如果用户名以 lj 开头则打印 欢迎尊贵的辣鸡用户 username 登陆!您有以下爱好 爱好1&爱好2&爱好3

lj打印的时候只要后边的用户名,不要lj_

把数据装到用名字当key的字典里,方便查找

data_dict = {}
for data in data_list:
# hobby_data = ' & '.join(data.split('|')[2].split('-')) # 把爱好切分重新连接
hobby_data = data.split('|')[2].replace("-",' & ') # 把爱好切分的第二种方法
data_dict[data.split('|')[0]] = [data.split('|')[1],hobby_data,'visit'] #增加键值对到字典

print(data_dict)

用户登录

def login():
tag=0
while tag<3: #循环3次
tag+=1
name_input = input("please input your name:").strip()
if name_input not in data_dict:
print(f'user {name_input} not exist, try again') # 输入姓名不存在则退出本次循环,重新输入
continue
password_input = input('please input your password:').strip()
if not(password_input.isdigit()) or len(password_input)!=3: # 输入密码格式不正确则退出本次循环,重新输入
print('password is ilegal,try again')
continue
elif password_input == data_dict[name_input][0]: # 输入密码正确则开始判断条件
if 'nb' in name_input and not name_input.startswith('lj'):
print(f'欢迎VIP用户 {name_input.replace("nb","")} 登陆!您有以下爱好 {data_dict[name_input][1]}.')
elif name_input.startswith('lj
'):
print(f'欢迎尊贵的辣鸡用户 {name_input[3:]} 登陆!您有以下爱好{data_dict[name_input][1]}.')
else:
print(f'欢迎用户 {name_input} 登陆!您有以下爱好{data_dict[name_input][1]}.')
break # 输入密码正确条件判断完成后结束循环
else:
print(f'wrong password') # 输入密码不正确退出本次循环
continue

用户注册

def register():
verify_code = 'qaz123456'
# 输入并校验注册姓名是否存在,存在则重新输入

# 输入并校验密码格式
tag_register = 0
while tag_register < 3:
    tag_register+=1
    name_register = input("please input your name:").strip()
    if name_register in data_dict:
        print(f"username {name_register} already exist,please input again:")
        continue
    password_register = input('please input your password with 3 numbers:').strip()
    if not (password_register.isdigit()) or len(password_register) != 3:  # 输入密码格式不正确则退出本次循环,重新输入
        print('password is ilegal,try again:')
        continue

    hobby_register =True           # 输入n个爱好,用enter结束
    hobby_list = []
    while hobby_register != "0":
        hobby_register = input('please input your hobby end with 0 ').strip()
        hobby_list.append(hobby_register)
    hobby_list.pop()
    verify_input = input('are you administrator? input the verify code:').strip()
    if verify_input == verify_code:
        role = 'admin'
    else:
        role = 'visit'
    break
data_dict[name_register]=[password_register,hobby_list,role]
# print(data_dict)

删除用户

def delete_find():
name_check = input("please input your username:")
password_check = input('please input your password:')
if name_check in data_dict and password_check == data_dict[name_check][0]:
if data_dict[name_check][2] and data_dict[name_check][2] == 'admin':
del_find = input("do you want to delete or find: del press 1, find press 2")
if del_find == '1':
all_one = input("do you want to delete all or one: all press a, one press the name")
if all_one == 'a':
data_dict.clear()
elif all_one in data_dict:
del data_dict[all_one]
else:
print('wrong input')
elif del_find == '2':
find_input = input('please input the name:')
if find_input in data_dict:
print(f'the information for {find_input}is: {data_dict[find_input]}')
else:
print('wrong input')
else:
print('you have no right to delete or find')
else:
print('wrong input')

功能选择,主界面

function_choices = '''1.login
2.register
3.delete
4.find'''
function_choices_dict = {}
funcsp = function_choices.split('\n')

print(funcsp)
for choice in funcsp:

choice = choice.split('.')
function_choices_dict[choice[0]]=choice[1]

print(function_choices_dict)

给3次功能选择机会

tag_ = 0
while tag_❤️:
tag_+=1

tag_func = 0
while tag_func<3:  # 给3次输入机会
    tag_func+=1
    function_input = input(f'please input your choice by the list:{function_choices}').strip()
    if function_input not in function_choices_dict:
        print(f'please input the right choice:')
        continue
    elif function_input =="1":   #按功能选择函数
        login()
    elif function_input =='2':
        register()
    elif function_input =='3':
        delete_find()
    else:
        tag_=3
posted @ 2024-04-02 15:37  zenopan  阅读(5)  评论(0编辑  收藏  举报