zoukankan      html  css  js  c++  java
  • 第二阶段---python基础--模拟登陆

    说明:

    1、用户原文件存储在文件中_userinfo

      userinfo文件内容:

      [['li','123'],['z','333']]

    2、判断是否存在登陆错误的用户_被锁定的用户_wrong_name2,没有创建,并写入用户文件头username,带逗号,锁定用户以'逗号'隔开;

    3、判断输入用户是否存在锁定账户中(取出用户名,存入列表,)

    4、逻辑控制,用户名,或秘密超过3次记录该用户的用户名到文件;

    import os
    if os.path.exists('wrong_name2'):
        file_wrong=open('wrong_name2')
        f=file_wrong.readline()
        lock_name=f.split(',')
        for i in lock_name:
            print(i)
        file_wrong.close()
    else:
        with open('wrong_name2','w') as f_wrong:
            f_wrong.write('username')
            f_wrong.write(',')
            lock_name=f_wrong.split(',')
            for i in lock_name:
                print(i)
            file_wrong.close()


    file=open('userinfo2')
    info=eval(file.readline())
    print(info)
    l_name=[]
    l_passwd=[]
    l_count=[]
    count=0
    for i in info:
        l_name.append(i[0])
    for k in info:
        l_passwd.append(i[1])




    while True and count<3:
        name=input('pls input your name:').strip()
        if name in lock_name:
            print('the count is locked...exit.')
            exit()
        while name in l_name and count<3:
            count=0
            while count<3:
                passwd=input('pls input your passwd:').strip()
                if passwd in l_passwd:
                    print('welcome')
                    break
                else:
                    count+=1
                    print('wrong passwd')
                    print(count)
            else:
                l_count.append(name)
                print(l_count)
                f_w=open('wrong_name2','a+')
                f_w.write(str(l_count[-1]))
                f_w.write(',')
                f_w.close()
                print('count>>>%s was locked...'%name)
                exit()
        else:
            count+=1
            print('wrong name...')
            continue
    else:
        l_count.append(name)
        f_w=open('wrong_name2','a+')
        f_w.write(str(l_count[-1]))
        f_w.write(',')
        print('count>>>%s was locked...'%name)

  • 相关阅读:
    leetcode44:wildcard
    Python实现决策树
    PCA实现
    js触摸事件
    js中的getBoundingClientRect()函数
    Java中timer的schedule()和schedualAtFixedRate()函数的区别
    nodejs中的exports和module.exports
    为什么MySQL数据库要用B+树存储索引
    浅谈微服务中的熔断,限流,降级
    缓存击穿、缓存穿透和缓存雪崩
  • 原文地址:https://www.cnblogs.com/santizhou/p/7409769.html
Copyright © 2011-2022 走看看