登录界面

时间:2019-07-28 00:13:09   收藏:0   阅读:110
技术分享图片
while 1:
    username =input (请输入你的注册账号:)
    userkey = input(请输入你的注册密码(只能是纯数字):)
    if userkey.isdigit():
        with open(数据存储,r+,encoding=utf-8) as f:
            f.write({} \n {}.format(username,userkey))
        print("注册成功")
        break
    else:
        print(请输入数字)
i = []
l = 0
while l < 3:
    user = input(请输入账号:)
    key1 = input(请输入密码:)
    with open(数据存储,r+,encoding=utf-8) as f:
            for line in  f:
                i.append(line)
                print(i)
                if user == i[0].strip() and key1 == i[1].strip():
                        print("登录成功")
                        break
                else:
                    print(登陆失败)
                    print(你还有{}次机会.format(l))
                l += 1
View Code

这个代码有问题,嗯.

不知为何,usrkey不能添加进入列表

待修改

修改完成

原因:将if循环列入了for循环中,导致每次只输入一个元素进入列表中

技术分享图片
while 1:
    username =input (请输入你的注册账号:)
    userkey = input(请输入你的注册密码(只能是纯数字):)
    if userkey.isdigit():
        with open(数据存储,r+,encoding=utf-8) as f:
            f.write({} \n {}.format(username,userkey))
        print("注册成功")
        break
    else:
        print(请输入数字)
i = []
l = 0
while l < 3:
    user = input(请输入账号:)
    key1 = input(请输入密码:)
    with open(数据存储,r+,encoding=utf-8) as f:
            for yihang in  f:
                i.append(yihang)
                print(i)
    if user == i[0].strip() and key1 == i[1].strip():
            print("登录成功")
            break
    else:
                print(登陆失败)
                print(你还有{}次机会.format(l))
                l += 1
View Code

 

原文:https://www.cnblogs.com/zly9527/p/11257206.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!