面向过程编程

"""
面向过程编程:就类似于设计一条流水线
    好处:
        将复杂的问题流程化 从而简单化 让人一目了然  可以明白什么是干什么的
    坏处:
        可扩展性较差   一旦需要修改 整体都会受到影响牵制一发 动则全身  因为你不直到哪里 用到了这个函数所以 要修改 是很麻烦的  稍有不注意那么整个代码就有问题
"""
# 注册功能
# 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
'%(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()
原文地址:https://www.cnblogs.com/yangxinpython/p/11192311.html