|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
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
else:
steps = 7 * (i + 1)
i = i + 1
if FIND == True:
print('阶梯数是:', steps)
else:
print('在程序限定的范围内找不到答案!')
这个是7的倍数问题 我想显示在100倍数以内所有满足的数字和对应的7的倍数
这是爱因斯坦阶梯问题,参考代码:
- steps = 7
- i = 1
- while i < 100:
- if (steps % 2 == 1) and (steps % 3 == 2) and (steps % 5 == 4) and (steps % 6 == 5):
- print('阶梯数是:', steps)
- steps = 7 * (i + 1)
- i = i + 1
复制代码
还可以这样改:
- steps = 7
- print("阶梯数是:", end="")
- while steps < 1000:
- if (steps % 2 == 1) and (steps % 3 == 2) and (steps % 5 == 4) and (steps % 6 == 5):
- print(steps, end=" ")
- steps = steps + 7
复制代码
|
|