python 作业10

问题:

0.请问下面表达式的值是什么?

 

>>> 3 == not 5

报错    ==  比 not  优先级高  所以出现了 3 == not  报错

 

 



1.

 

>>> 3 or 5 and 0

3    先计算5 and 0   得到0   随后 3 or 0     根据短路逻辑可以得出是 3

2.

 

>>> 3 and 5 + True or False

6       true 相当于 1  false 相当于 0    3and 5  结果5  5+1 =6

3.

 

>>> 0 and not 1 or not 2 and 3 or 4 and not 5

按照 非与或 这个优先级 划分   0 and False or False and 3 or 4 and False

 0 or False or False

最后得到false

4.

 

>>> 1 == 2 < 3

false

这个链式比较,拆出来是 1 == 2 and 2 < 3,而不是先 (1 == 2) < 3,得到的是两个截然不同的结果

5.请将下面的链式比较转换为使用 and 的普通比较。

>>> 1 < 2 > 3 < 4 < 5

1 < 2 and 2 > 3  and 3 < 4 and 4 < 5

动动手:

0.爱因斯坦曾出过这样一道有趣的数学题:

有一个长阶梯,若每步上 2 阶,最后剩 1 阶;若每步上 3 阶,最后剩 2 阶;若每步上 5 阶,最后剩 4 阶;若每步上 6 阶,最后剩 5 阶;只有每步上 7 阶,最后刚好一阶也不剩。

求解该阶梯的最终数量?

steps = 7
i = 1
FIND = False

while i < 100:
    if  (steps % 2 == 1)and(steps % 3 == 2)and(steps % 5 == 4)and(steps % 6 == 5):
        FIND = True
        break
    else:
        steps = 7 *(i+1)
    i = i + 1

if FIND == True:
    print('阶梯数是:', steps)

 

 

 
posted @ 2022-06-27 12:20  DICEi  阅读(71)  评论(0)    收藏  举报