zoukankan      html  css  js  c++  java
  • 模拟登录

    #coding:utf-8
    """
    1. 用户输入帐号密码进行登陆
    2. 用户信息保存在文件内
    3. 用户密码输入错误三次后锁定用户
    """



    dic={
    'egon1':{'password':'123','count':0},
    'egon2':{'password':'123','count':0},
    'egon3':{'password':'123','count':0},
    }
    flag=True
    while flag:
    name=input('type your name:').strip()
    with open('a.txt','r',encoding='utf-8') as red_user:
    if name in red_user.read().split('|'):
    print("账户已锁定")
    continue
    if name not in dic:
    print('name is not in dic')
    continue
    else:
    while flag:
    passwd=input('type your passwd:')
    if passwd!=dic[name]['password'] and dic[name]['count']<=2:
    print('passwd is wrong')
    dic[name]['count']+=1
    continue
    elif dic[name]['count']>2:
    print("chao guo 3 ci")
    user=open('a.txt','a',encoding='utf-8')
    user.write(name+'|')
    user.close()
    break
    if passwd==dic[name]['password']:
    print("login success")
    flag=False






  • 相关阅读:
    LeetCode-434-字符串中的单词数
    LeetCode-415-字符串相加
    字符串
    序列
    元组
    列表
    repr()与str的区别
    输出函数print()
    输入函数input()
    MySQL中快速复制数据表方法汇总
  • 原文地址:https://www.cnblogs.com/lalashou/p/7867415.html
Copyright © 2011-2022 走看看