[root@sun ~]# cat 7.py #!/usr/bin/python # -*- coding=UTF-8 -*- usera_name = 'usera' usera_passwd = 'aresu' usera_status = 'on' userb_name = 'userb' userb_passwd = 'bresu' userb_status = 'on' ng = 0 name = raw_input('请输入用户名:') while ng < 3: if name == usera_name: passwd = raw_input('请输入密码 :') if passwd == usera_passwd: print '欢迎回来 usera !!!' break else: ng += 1 if ng == 3: print '密码输入错误三次,账号已锁定 !!!' usera_status = 'off' break elif name == userb_name: passwd = raw_input('请输入密码 :') if passwd == userb_passwd: print '欢迎回来 userb !!!' break else: ng += 1 if ng == 3: print '密码输入错误三次,账号已锁定 !!!' usera_status = 'off' break else: print '用户不存在,请重新执行' break print usera_name,usera_status print userb_name,userb_status [root@sun ~]# python 7.py 请输入用户名:usera 请输入密码 :1 请输入密码 :2 请输入密码 :3 密码输入错误三次,账号已锁定 !!! usera off userb on [root@sun ~]# python 7.py 请输入用户名:userb 请输入密码 :3 请输入密码 :2 请输入密码 :1 密码输入错误三次,账号已锁定 !!! usera off userb on [root@sun ~]# python 7.py 请输入用户名:sun 用户不存在,请重新执行 usera on userb on [root@sun ~]# python 7.py 请输入用户名:usera 请输入密码 :aresu 欢迎回来 usera !!! usera on userb on