• 面向过程编程


    面向过程编程

        核心过程二字,过程指的是解决问题的步骤,即先干什么、再干什么、然后干什么...

        基于该思想编写程序就好比在设计一条流水线,是一种机械式的思维方式

        优点

            复杂的问题流程化、进而简单化

        缺点

            扩展性极差

    '''

    # 接收用户输入用户名,进行用户名合法性校验,拿到合法的用户名

    def check_user():

        while True:

            name = input('username>>').strip()

            if name.isalpha():

               return name

            else:

                print('用户名必须为字母,傻叉')

    # 接收用户输入密码,进行密码合法性校验,拿到合法的密码

    def check_pwd():

        while True:

            pwd1=input('password>>: ').strip()

            if len(pwd1) < 5:

                print('密码的长度至少5位')

                continue

            pwd2=input('again>>: ').strip()

            if pwd1 == pwd2:

                return pwd1

            else:

                print('两次输入的密码不一致')

    def check_age():

        pass

    # pwd=check_pwd()

    # print(pwd)

    # 将合法的用户名与密码写入文件

    def insert(user,pwd,age,path='db.txt'):

        with open(path,mode='a',encoding='utf-8') as f:

            f.write('%s:%s:%s ' %(user,pwd,age))

    def register():

        user=check_user()

        pwd=check_pwd()

        age=check_age()

        insert(user,pwd,age)

        print('register successfull')

    register()

    # 用户功能层

    def register():

        while True: # 检测用户名

            name=input('username>>: ').strip()

            #检测用户是否重复,如果重复了则重新输入,否则break

            res=check_user_interface(name)

            if res:

                print('用户存在')

            else:

                break

        while True: # 检测密码

            pwd1 = input('pwd1>>: ').strip()

            pwd2 = input('pwd2>>: ').strip()

            if pwd1 != pwd2:

                print('两次输入密码不一致,重新输入')

            else:

                break

    def tell_info():

        name=input('>>: ').strip()

        info=select(name)

        print(info)

    # 接口层

    def check_user_interface(name):

        res = select(name)  # res=['egon','123']

        if res:

            return True

        else:

            return False

    # 数据处理层

    def select(name):

        with open('db.txt', 'r', encoding='utf-8') as f:

            for line in f:

                info = line.strip(' ').split(':') #info=['egon','123']

                if name == info[0]:

                    return info

  • 相关阅读:
    Android为TV端助力:adb查找包名位置
    Android为TV端助力:RecyclerView更新数据时焦点丢失
    一个IOS自动化打包的脚本
    关于IOS免证书真机安装的过程和问题
    使用CoreAnimation 实现相机拍摄照片之后动画效果
    解决路由器无线中继连接不稳定的问题
    解决 an app id with identifier is not available. please enter a different string. xcode 7.3
    CoreText 关键性常用函数说明
    解决Xcode 7 http无法使用的问题
    解决IOS9 下在App中无法打开其他应用的问题
  • 原文地址:https://www.cnblogs.com/wanglecn/p/9204389.html
Copyright © 2020-2023  润新知