zoukankan      html  css  js  c++  java
  • 控制流程之if判断

     语法1

     if 条件:

         代码1

         代码2

         代码3

         ...

     cls='human'

     sex='female'

     age=18

     if cls == 'human' and sex == 'female' and age > 16 and age < 22:

         print('开始表白')

     print('end....')

     语法2

     if 条件:

         代码1

         代码2

         代码3

         ...

     else:

         代码1

         代码2

         代码3

         ...

     cls='human'

     sex='female'

     age=38

     if cls == 'human' and sex == 'female' and age > 16 and age < 22:

         print('开始表白')

     else:

         print('阿姨好')

     print('end....')

     语法3

     if 条件1:

         代码1

         代码2

         代码3

         ...

     elif 条件2:

         代码1

         代码2

         代码3

         ...

     elif 条件3:

         代码1

         代码2

         代码3

         ...

     ............

     else:

         代码1

         代码2

         代码3

         ...

    '''

    如果:成绩>=90,那么:优秀

    如果成绩>=80<90,那么:良好

    如果成绩>=70<80,那么:普通

    其他情况:很差

    '''

     score=input('your score: ') #score='73'

     score=int(score) #score=73

     if score >= 90:

         print('优秀')

     elif score >= 80:

         print('良好')

     elif score >= 70:

         print('普通')

     else:

         print('很差')

     user_from_db='egon'

     pwd_from_db='123'

     user_from_inp=input('username>>>: ')

     pwd_from_inp=input('password>>>: ')

     if user_from_inp == user_from_db and pwd_from_inp == pwd_from_db:

         print('login successfull')

     else:

         print('user or password error')

    if的嵌套

    cls='human'

    sex='female'

    age=18

    is_success=False

    if cls == 'human' and sex == 'female' and age > 16 and age < 22:

        print('开始表白...')

        if is_success:

            print('在一起')

        else:

            print('我逗你玩呢....')

    else:

        print('阿姨好')

    print('end....')

  • 相关阅读:
    Why use strong named assemblies?
    Dependency Walker
    “等一下,我碰!”——常见的2D碰撞检测
    MOBA游戏的网络同步技术
    VS2017如何配置openGL环境
    UE4关于Oculus Rift (VR)开发忠告
    UE4 的json读写方式
    Blueprint 编译概述
    UE4编码规范
    Unreal Enginer4特性介绍
  • 原文地址:https://www.cnblogs.com/wanglecn/p/9112518.html
Copyright © 2011-2022 走看看