Exercise_6

Exercise 6 : Operators

Test :

  1. floor 除法 : 返回最近的整数

    3.0 // 2.0 #1.0

  2. a < b < c 等价于 a < b and b < c

  3. 5 ** -2 #0.04

  4. not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9

    4 (preference : not > and > or )

    and 和 or 均返回决定表达式结果的值

    x and y ,x 为真,返回y;x为假,返回x

    x or y, x为真,返回x;x为假,返回y

    not x , x为真,返回False;x为假,返回True

Try :

100以内的奇数:

1
2
3
4
5
6
7
i = 0
while i<100:
if i%2 !=0:
print(i, ' ')
i += 1
else:
i += 1

中国剩余定理问题 :

1
2
3
4
5
6
7
i = 1
while i < 2000:
if (i % 2 == 1) and (i % 3 == 2) and (i % 5 == 4) and (i % 6 == 5) and (i % 7 == 0):
print(i)
i += 1
else:
i += 1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
x = 7
i = 1
flag = 0
while i<= 1000:
if (x%2 ==1) and (x%3 == 2) and (x%5 == 4) and (x%6 == 5):
flag = 1
else:
x = 7 * (i+1)
i += 1

if flag == 1:
print('阶梯数为:', x)
else:
print('No result!')

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!