zoukankan      html  css  js  c++  java
  • 面向过程编程

    """
    面向过程编程:就类似于设计一条流水线
        好处:
            将复杂的问题流程化 从而简单化 让人一目了然  可以明白什么是干什么的
        坏处:
            可扩展性较差   一旦需要修改 整体都会受到影响牵制一发 动则全身  因为你不直到哪里 用到了这个函数所以 要修改 是很麻烦的  稍有不注意那么整个代码就有问题
    """
    # 注册功能
    # 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()
  • 相关阅读:
    常用排序算法(七)归并排序
    常用排序算法(六)堆排序
    常用排序算法(五)选择排序
    常用排序算法(四)希尔排序
    常用排序算法(三)直接插入排序
    常用排序算法(二)快速排序
    常用排序算法(一)冒泡排序
    Linux内核中双向链表的经典实现
    回溯法
    迪杰斯特拉Dijkstra算法介绍
  • 原文地址:https://www.cnblogs.com/yangxinpython/p/11192311.html
Copyright © 2011-2022 走看看