zoukankan      html  css  js  c++  java
  • 2018.09.14python学习第四天part1

    流程控制之if判断

    1.什么是if判断?(what)

    判断一个if条件,如果成立则做什么,如果不成立则做什么

    2.为什么要有if判断?(why)

    为了让电脑像人一样有判断能力。(赋予它逻辑判断)

    3.如何使用if判断?(how)

    #语法一:

     if条件1:

      code1

      code2

      ........

    age=18
    if age==18:
        print("hello i love u")

    #语法二:

    if条件:

      code1

      code2

      .......

    else:

      code1

      code2

      ..........

    age=18
    sex="female"
    is_beautiful=True
    
    if age>16 and age<30 and sex=="female" and is_beautiful:
        print("i love u)
    else:
        print("阿姨你好")

    #语法三:(if的嵌套)

    if条件1:

      if条件2:

        code1

        code2

        .....

      code2

      code3

      .......

    age=18
    sex=female
    is_beautiful=True
    is_successful=True
    
    if age>16 and age<30 and sex==female and is_beautiful:
        print("开始表白")
        if is_successful:
            print("在一起")
        else:
            print("我有钱")
    else:
        print("阿姨再见")

    #语法四:

    if 条件1:

      code1

      code2

    elif 条件2:

      code3

      code4

    elif 条件3:

      code5

      code6

    ..........

    else:

      code7

      code8

    score = input(" your score")
    score=int(score)
    if score>90:
        print("very good")
    elif score<=80:
        print("good")
    elif score<=70:
        print("just so so")
    else:
        print("bad")

    ps:  1.注意if条件结束以后一定要用:

      2.如果一行代码太长的话可以用/分隔后另起一行

      3.同一子代码块中的代码缩进应该相同

  • 相关阅读:
    共享内存
    文件IO函数和标准IO库的区别
    链表程序
    flash_header.S ( freescale imx6 board)
    深入理解二维数组
    putchar和puts
    指针目标
    C语言:break和continue
    C语言:输入输出
    python lambda
  • 原文地址:https://www.cnblogs.com/hello-yuanjing/p/9646903.html
Copyright © 2011-2022 走看看