PYTHON-文件处理-练习

#
# 一、实现用户注册功能
# 思路:
# 用户输入用户名、密码
# 将用户输入的内容按照固定的格式,比如:egon:123,存入文件
# 可以往一个文件中重复注册新的用户名和密码
# 附加:
# 1、对输入的用户名进行合法性监测,不能以数字开头,且如果输入的用户名已存在于文件中则要求用户重新输入
# 2、对输入的密码进行合法性监测,密码的长度至少6位,并且不能包含特殊字符*&$
# y=[]
# print('注册请填写以下信息')
# tag=True
# with open(r'db.txt', mode='rt', encoding='utf-8')as x:
# for data_name in x:
# d_name = data_name.strip('\n').split(':')
# y.append(d_name[0])
# # print(y)
# while tag:
# name = input('username>>>').strip()
# if name[0].isdigit():
# print('不能以数字开头,请重新输入')
# continue
# if name in y:
# print('已被注册,请重新输入')
# continue
# while tag:
# pwd = input('password>>>').strip()
# if len(pwd)<6:
# print('密码的长度至少6位')
# continue
# if pwd.find('$') != -1:
# print('不能包含特殊字符*&$')
# continue
# else: print('注册成功')
# with open(r'db.txt', mode='at', encoding='utf-8')as f:
# data = '%s:%s\n' % (name, pwd)
# f.write(data)
# tag = False # 二、实现用户验证功能更:
# 思路:
# 用户输入账号密码,从文件中读出账号密码,与用户输入的进行比对
# 附加:新建黑名单文件,同一个账号名输错三次则将用户名写入黑名单文件中,
# 如果用户输入的用户名存在于黑名单中则直接退出 # y=[]
# z=[]
# b=[]
# tag=True
# count=0
# with open(r'db.txt', mode='rt', encoding='utf-8')as x,open(r'black.txt', mode='rt', encoding='utf-8')as a:
# for data_name in x:
# d_name = data_name.strip('\n').split(':')
# y.append(d_name[0])
# z.append(d_name[1])
# for data_black_name in a:
# b_name = data_black_name.strip('\n')
# b.append(b_name)
# while tag:
# name=input('username>>>').strip()
# if name in b:
# print('黑名单用户')
# break
# if name not in y:
# print('用户名不存在')
# continue
# while tag:
# pwd = input('password>>>').strip()
# if count>=2:
# print('输错三次,已列为黑名单')
# with open(r'black.txt',mode='at',encoding='utf-8') as f:
# f.write('%s\n' %name)
# tag = False
# break
# if pwd not in z:
# print('密码不存在')
# count+=1
# else:
# print('登录成功')
# tag=False # y=[]
# z=[]
# b=[]
# tag=True
# count=0
# with open(r'db.txt', mode='rt', encoding='utf-8')as x,open(r'black.txt', mode='rt', encoding='utf-8')as a:
# for data_name in x:
# d_name = data_name.strip('\n').split(':')
# y.append(d_name[0])
# z.append(d_name)
# print(z)
# for data_black_name in a:
# b_name = data_black_name.strip('\n')
# b.append(b_name)
# while tag:
# name=input('username>>>').strip()
# if name in b:
# print('黑名单用户')
# break
# if name not in y:
# print('用户名不存在')
# continue
# while tag:
# pwd = input('password>>>').strip()
# if count>2:
# print('输错三次,已列为黑名单')
# with open(r'black.txt',mode='at',encoding='utf-8') as f:
# f.write('%s\n' %name)
# tag = False
# break
# if [name,pwd] not in z:
# print('密码不存在')
# count+=1
# else:
# print('登录成功')
# tag=False
上一篇:移动端中遇到的坑(bug)!!!


下一篇:js原生ajax与jquery的ajax的用法区别