码迷,mamicode.com
首页 > 编程语言 > 详细

python学习 day1 登陆

时间:2016-05-13 09:38:21      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:

#/usr/bin/env python3
#coding:utf-8

import os
import sys
import getpass
import json


storage_user_file = "./username.py"
correct_user = "kk"
correct_pass = "kk"

for i in range(3):
    existing_users_dict = json.load(open(storage_user_file,‘r‘))
    get_user = input("please your username ")
    get_pass = input("please your password ")
    if correct_user == get_user and correct_pass == get_pass:
        print ("Welcome to login..")
        break
    else:
        if get_user in existing_users_dict:
            if existing_users_dict[get_user] >= 3:
                print ("You are locked")
                break
            else:
                existing_users_dict[get_user]+=1
                json.dump(existing_users_dict,open(storage_user_file,"w"))
                print ("The user name or password you entered is incorrect.")
        else:
            existing_users_dict[get_user] = 1
            json.dump(existing_users_dict,open(storage_user_file,"w"))
            print ("The user name or password you entered is incorrect.")

python学习 day1 登陆

标签:

原文地址:http://www.cnblogs.com/guokaikai/p/5485268.html

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