【Python3】Python简单的登录小程序

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:Chuncheng.Fan <xmzncc@gmail.com>


f1 = open('db','r')
data = f1.read()
f1.close()

# 1.格式化数据

user_info_list = []
user_str_list = data.split('\n')
for item in user_str_list:
    temp = item.split('|')
    v = {
        'name': temp[0],
        'pwd': temp[1],
        'times': int(temp[2])
    }
    user_info_list.append(v)
print(user_info_list)

user_login= []
flag = True
exit_flag = 3

while flag:
    username = input('请输入账号:')
    for item  in user_info_list:
        if  username == item['name']:
            if int(item['times']) < exit_flag:
                password = input('请输入密码:')
                if password == item['pwd']:
                    print('欢迎登陆!')
                    item['times'] = 0
                    flag = False
                    user_login = item
                    break
                else:
                    print('账号或密码错误,请重新输入')
                    item['times'] = int(item['times']) + 1
                    break
            else:
                print('账号已经锁定。')
                exit()
        else:
            print('账号不存在,请重新输入')
            break
    原文作者:Carson
    原文地址: https://segmentfault.com/a/1190000009367325
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞