""""""
"""
面向过程编程:就类似于设计一条流水线
好处:
将复杂的问题流程化 从而简单化
坏处:
可扩展性较差 一旦需要修改 整体都会受到影响
"""
# 注册功能
# 1.获取用户输入
def get_info():
while True:
username = input(">>>:").strip()
if not username.isalpha(): # 判断字符串不能包含数字
print('不能包含数字')
continue
password = input('>>>:').strip()
confirm_password = input("confirm>>>:").strip()
if password == confirm_password:
d = {
'1':'user',
'2':'admin'
}
while True:
print("""
1 普通用户
2 管理员
""")
choice = input('please choice user type to register>>>:').strip()
if choice not in d:continue
user_type = d.get(choice)
operate_data(username,password,user_type)
break
else:
print('两次密码不一致')
# 2.处理用户信息
def operate_data(username,password,user_type):
# jason|123
res = '%s|%s|%s\n'%(username,password,user_type)
save_data(res,'userinfo.txt')
# 3.存储到文件中
def save_data(res,file_name):
with open(file_name,'a',encoding='utf-8') as f:
f.write(res)
def register():
get_info()
register()