码迷,mamicode.com
首页 > 其他好文 > 详细

登录界面

时间:2019-07-27 23:57:30      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:display   git   alt   密码   strip   use   form   ide   enc   

技术图片
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

 

登录界面

标签:display   git   alt   密码   strip   use   form   ide   enc   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!