当前位置: 移动技术网 > IT编程>脚本编程>Python > 2020Python练习七

2020Python练习七

2020年03月16日  | 移动技术网IT编程  | 我要评论

北京水云居,办事快的成语,霸宠傲娇小情人

2020python练习七

@2020.3.15

周末综合作业:


1、编写用户登录接口
#1、输入账号密码完成验证,验证通过后输出"登录成功"
#2、可以登录不同的用户
#3、同一账号输错三次锁定,(提示:锁定的用户存入文件中,这样才能保证程序关闭后,该用户仍然被锁定) 

username1 = input('请输入你的名字:').strip()
usercode1 = input('请输入你的密码:').strip()
count=0
with open(r'd:\0tempt\db.txt',mode='rt',encoding='utf-8') as f:
    for line in f: #把用户输入的名字和密码与读出的内容作对比
        username,usercode=line.strip('').split(':')
        if username1 == username and usercode1 == usercode:
            print('登录成功')
            break
        else:
            print('账号或密码错误,请重试')
            count+=1
    else:
        print('账号或密码输错三次,账户已被锁定,请申请找回或修改密码')
        with open(r'd:\0tempt\clockeduser.txt',mode='wt',encoding='utf-8') as f:
            f.write('{}:{}'.format(username1,usercode1))

 

 

2、编写程序实现用户注册后,可以登录

提示:
while true:

while true:
    msg = """
    0 退出
    1 登录
    2 注册
    """
    print(msg)
    cmd = input('请输入命令编号>>: ').strip()
    if not cmd.isdigit():
        print('必须输入命令编号的数字,傻叉')
        continue

    if cmd == '0':
        break
    elif cmd == '1':
        # 登录功能代码(附加:可以把之前的循环嵌套,三次输错退出引入过来)
   count=0
with open(r'd:\0tempt\db.txt',mode='rt',encoding='utf-8') as f:
    for line in f: #把用户输入的名字和密码与读出的内容作对比
        username,usercode=line.strip('').split(':')
        if username1 == username and usercode1 == usercode:
            print('登录成功')
            break
        else:
            print('账号或密码错误,请重试')
            count+=1
    else:
        print('账号或密码输错三次,账户已被锁定,请申请找回或修改密码')
        with open(r'd:\0tempt\clockeduser.txt',mode='wt',encoding='utf-8') as f:
            f.write('{}:{}'.format(username1,usercode1))
        
    elif cmd == '2':
        # 注册功能代码
         print("注册账号".center(40,"="))
        info = {}
        name = input("账号名:").strip()
        pwd = input("账号密码:").strip()
        # 读取文件中已存在的账号密码信息
        with open("test1","r",encoding="utf-8") as f:
            for line in f:
                user_name, password = line.strip().split("-")
                info[user_name] = password
    else:
        print('输入的命令不存在')

 

 


msg = """
0 退出
1 登录
2 注册
"""
print(msg)
cmd = input('请输入命令编号>>: ').strip()
if not cmd.isdigit():
print('必须输入命令编号的数字,傻叉')
continue

if cmd == '0':
break
elif cmd == '1':
# 登录功能代码(附加:可以把之前的循环嵌套,三次输错退出引入过来)
pass
elif cmd == '2':
# 注册功能代码
pass
else:
print('输入的命令不存在')

 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网