正在看《老男孩高薪必备]Python高级运维编程实战精品入门进阶》上面的习题:

实现用户名密码登陆,输入错误3次后锁定用户

自己写的,代码很烂但是总的来说实现了。

#!/usr/bin/env python

#_*_coding:utf-8 _*_

import sys

conter = 0

while True:

       user_name = raw_input("请输入用户名:")

       if len(user_name)==0 or user_name != "Hans":

               continue

       while True:

               if conter < 3:

                       passwd = raw_input("请输入密码:")

                       if len(passwd) == 0 or passwd != "123":

                               print "密码错误,请重新输入."

                               conter += 1

                               continue

                       else:

                               print "欢迎登录."

               else:

                       print "用户被锁定."

                       sys.exit()

               break

       break


   今天看了wuyuehanbing的几篇博客很有感触 wuyuehanbing 很强大,努力向他学习。

下面是他的两篇文章:

http://bbs.51cto.com/thread-1094141-1.html

http://bbs.51cto.com/thread-1067920-1.html