黄金猫 发表于 2021-8-28 17:22:00

011

0.False
1.3
2.6
3.0
4.True
5.1<2 and 2>3 and 3<4 and 4<5
-------------------------------------dds
0.
steps = 7
i = 1
FIND = False

while i < 1000:
    if i%2 ==1 and i%3 == 2 and i%5 == 4 and i%6 == 5 and i%7 == 0:
      FIND = True
      steps = i
      break
    else:
      FIND = False
    i = i + 1

if FIND == True:
    print('阶梯数是:', steps)
else:
    print('在程序限定的范围内找不到答案!')

**************************************
改错:
0.报错
3.false
4.false,注意,这个链式比较,拆出来是 1 == 2 and 2 < 3,而不是先 (1 == 2) < 3,得到的是两个截然不同的结果。
------------------
dds
0.
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)
    print(i,steps)
    i = i + 1

if FIND == True:
    print('阶梯数是:', steps)
else:
    print('在程序限定的范围内找不到答案!')

首先steps是7 的倍数,其次,每次增加7,看是否匹配。
页: [1]
查看完整版本: 011