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

    语法一:
      if 条件:
      # 条件成立时执行的子代码块
      代码1
      代码2
      代码3

    sex='female'
    age=18
    is_beautiful=True
    
    if sex == 'female' and age > 16 and age < 20 and is_beautiful:
        print('开始表白。。。')
    
    print('other code1...')
    print('other code2...')
    print('other code3...')
    

    语法二:
    if 条件:
      # 条件成立时执行的子代码块
      代码1
      代码2
      代码3
      else:
      # 条件不成立时执行的子代码块
      代码1
      代码2
      代码3

    sex='female'
    age=38
    is_beautiful=True
    
    if sex == 'female' and age > 16 and age < 20 and is_beautiful:
        print('开始表白。。。')
    else:
        print('阿姨好。。。')
    
    
    print('other code1...')
    print('other code2...')
    print('other code3...')
    

     

    语法三:
    if 条件1:
      if 条件2:
        代码1
        代码2
        代码3

     

    sex='female'
    age=18
    is_beautiful=True
    is_successful=True
    height=1.70
    
    
    if sex == 'female' and age > 16 and age < 20 and is_beautiful 
            and height > 1.60 and height < 1.80: 
        print('开始表白。。。')
        if is_successful:
            print('在一起。。。')
        else:
            print('什么爱情不爱情的,爱nmlgb的爱情,爱nmlg啊.')
    else:
        print('阿姨好。。。')
    
    
    print('other code1...')
    print('other code2...')
    print('other code3...')
    

     

    语法四:
    if 条件1:
      代码1
      代码2
      代码3
    elif 条件2:
      代码1
      代码2
      代码3
    elif 条件3:
      代码1
      代码2
      代码3
    .......
    else:
      代码1
      代码2
      代码3

     

  • 相关阅读:
    vue+element的el-menu组件实现路由跳转及当前项的设置
    继承与多态
    八、使用for解决简单的问题
    六、Js数组的使用方法
    五、JS操作HTML方法
    四、初步入门JS的用法
    三、html总结
    二、表格<table>的使用
    一、初步接触html,基本标签和ul、ol的用法
    运算符的分类
  • 原文地址:https://www.cnblogs.com/king-home/p/10574471.html
Copyright © 2011-2022 走看看