天天看点

Python 入门教程 5 ---- Conditionals & Control Flow

 第一节

     1 介绍Python利用有6种比较的方式 == , != , > , >= , < , <=

     2 比较后的结果是True或者是False

     3 练习

        1 把bool_one的值设置为 17 < 118%100

        2 把bool_two的值设置为 100 == 33*3 + 1

        3 把bool_two的值设置为 19 <= 2**4

        4 把bool_four的值设置为 -22 >= -18

        5 把bool_five的值设置为 99 != 98+1

 第二节

    1 介绍了比较的两边不只是数值,也可以是两个表达式

    2 练习

       1 把bool_one的值设置为 20 + -10*2 > 10%3%2

       2 把bool_two的值设置为 (10+17)**2 == 3**6

       3 把bool_two的值设置为 1**2**3 <= -(-(-1))

       4 把bool_four的值设置为 40/20*4 >= -4**2

       5 把bool_five的值设置为 100**0.5 != 6+4

 第三节

    1 介绍了Python里面还有一种数据类型是booleans,值为True或者是False

    2 练习:根据题目的意思来设置右边的表达式

 第四节

    1 介绍了第一种连接符and的使用,只有and的两边都是True那么结果才能为True

       1 设置变量bool_one的值为False and False

       2 设置变量bool_two的值为-(-(-(-2))) == -2 and 4 >= 16**0.5

       3 设置变量bool_three的值为19%4 != 300/10/10 and False

       4 设置变量bool_four的值为-(1**2) < 2**0 and 10%10 <= 20-10*2

       5 设置变量bool_five的值为True and True

 第五节

    1 介绍了第二种连接符or的使用,只要or的两边有一个True那么结果才能为True

       1 设置变量bool_one的值为2**3 == 108%100 or 'Cleese' == 'King Arthur'

       2 设置变量bool_two的值为True or False

       3 设置变量bool_three的值为100**0.5 >= 50 or False

       4 设置变量bool_four的值为True or True

       5 设置变量bool_five的值为1**100 == 100**1 or 3*2*1 != 3+2+1

 第六节

    1 介绍第三种连接符not , 如果是not True那么结果为False,not False结果为True

       1 设置变量bool_one的值为not True

       2 设置变量bool_two的值为not 3**4 < 4**3

       3 设置变量bool_three的值为not 10%3 <= 10%2

       4 设置变量bool_four的值为not 3**2+4**2 != 5**2

       5 设置变量bool_five的值为not not False

 第七节

    1 介绍了由于表达式很多所以我们经常使用()来把一些表达式括起来,这样比较具有可读性

       1 设置变量bool_one的值为False or (not True) and True

       2 设置变量bool_two的值为False and (not True) or True 

       3 设置变量bool_three的值为True and not (False or False)

       4 设置变量bool_four的值为not (not True) or False and (not True)

       5 设置变量bool_five的值为False or not (True and True)

 第八节

    1 练习:请至少使用and,or,not来完成以下的练习

 第九节

    1 介绍了条件语句if

    2 if的格式如下, 比如

    3 另外还有这elif 以及else,格式如下

     4 练习:设置变量response的值为'Y'

 第十节

    1 介绍了if的格式

    2 练习:在两个函数里面加入两个加入条件语句,能够成功输出

 第十一节

     1 介绍了else这个条件语句

     2 练习:完成函数里面else条件语句

 第十二节

     1 介绍了另外一种条件语句elif的使用

     2 练习:在函数里面第二行补上answer > 5, 第四行补上answer < 5 , 从而完成这个函数

 第十三节

    1 练习:利用之前学的比较以及连接符以及条件语句补全函数。所有的都要出现至少一次