标签:python
编写一个登陆接口,要求如下
import os
count = 0
#读取用户列表
user_check = open(‘userlist.txt‘,‘r‘)
userlist = user_check.read()
user_check.close()
#读取锁定用户列表
user_lock = open(‘userlock.txt‘,‘r‘)
lock = user_lock.read()
user_lock.close()
username = input("输入用户名:")
while count < 3:
passwd = input("请输入密码:")
if username in lock:
print("账号已锁定,请联系管理员")
break
else:
if username in userlist:
if passwd == ‘123456‘:
print("welcome "+username)
break
else:
print("密码错误")
count += 1
else:
print("您输入的账号不存在")
break
else:
print("连续三次输错密码,账号被错定")
#开始将连续三次输错密码的账号写入锁定用户列表
add_lock = open(‘userlock.txt‘,‘a‘)
add_lock.write(username)
add_lock.close()
标签:python
原文地址:http://blog.51cto.com/ycentos/2113142