# 初学者的起步,对于开始的流程图结构还不太熟悉

#   思考: 1,write()与writelines()的区别,前者确定为字符串,后者为序列(列表,字典、元组等),自动为你迭代输入
#               2. 文件结构的构建,选择什么样的序列存储数据,如何使用有待加强

       3.文件的读写操作,读写格式的设置 r ,a,w三种类别,分为只读,只追加、只覆盖写;然后延伸至rb,wb,ab读写二进制文件应用于视频与图片的读写;其次r+为可读写两种操作 w+为可读写两种操作(f覆盖) a+为追加读写两种操作,最后rb+,wb+,ab+

 
 # import getpass

 def read_lock():
f = open('lockfile', encoding='utf-8')
user_lock_info = f.read().split()
f.close()
return user_lock_info def save_lock(lockname):
s = open("lockfile", 'a', encoding='utf-8')
s.writelines(lockname)
s.close() def read_log():
user_log = {}
f = open('log', encoding='utf-8')
user_log_info = f.readlines()
f.close()
for i in user_log_info:
user = i.split(" ", 2)
user_log[user[0]] = user[1]
# print(user_log)
return user_log count = 0
while count < 3:
username = input('username:')
# password = getpass.getpass("password:")
lock = read_lock()
user_log = read_log()
if username not in user_log:
print("---该用户不存在---")
continue
if username in lock:
print("---Your account is Locked---")
continue
password = input("password:")
if user_log[username] == password:
print("---welcome to log in---")
break
else:
count += 1
print("----Your account or password is wrong,please input again!!-----")
else:
save_lock(username)
print(">>>>>The times of your wrong input is more than %s times<<<<<<\n "
">>>>>so your account is locked<<<<<<" % count)


05-14 09:23