鱼C论坛

 找回密码
 立即注册
查看: 1307|回复: 2

[已解决]python

[复制链接]
发表于 2022-5-9 14:53:59 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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的倍数
最佳答案
2022-5-9 15:02:04

这是爱因斯坦阶梯问题,参考代码:

  1. steps = 7
  2. i = 1
  3. while i < 100:
  4.     if (steps % 2 == 1) and (steps % 3 == 2) and (steps % 5 == 4) and (steps % 6 == 5):
  5.         print('阶梯数是:', steps)
  6.     steps = 7 * (i + 1)
  7.     i = i + 1
复制代码


还可以这样改:
  1. steps = 7
  2. print("阶梯数是:", end="")
  3. while steps < 1000:
  4.     if (steps % 2 == 1) and (steps % 3 == 2) and (steps % 5 == 4) and (steps % 6 == 5):
  5.         print(steps, end=" ")
  6.     steps = steps + 7
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-5-9 15:02:04 | 显示全部楼层    本楼为最佳答案   

这是爱因斯坦阶梯问题,参考代码:

  1. steps = 7
  2. i = 1
  3. while i < 100:
  4.     if (steps % 2 == 1) and (steps % 3 == 2) and (steps % 5 == 4) and (steps % 6 == 5):
  5.         print('阶梯数是:', steps)
  6.     steps = 7 * (i + 1)
  7.     i = i + 1
复制代码


还可以这样改:
  1. steps = 7
  2. print("阶梯数是:", end="")
  3. while steps < 1000:
  4.     if (steps % 2 == 1) and (steps % 3 == 2) and (steps % 5 == 4) and (steps % 6 == 5):
  5.         print(steps, end=" ")
  6.     steps = steps + 7
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2022-5-9 15:04:20 | 显示全部楼层
  1. steps = 7
  2. i = 1
  3. while i < 100:
  4.     if (steps % 2 == 1) and (steps % 3 == 2) and (steps % 5 == 4) and (steps % 6 == 5):
  5.         print(f'满足条件的数字:{i},对应的7的倍数:{steps}')
  6.     else:
  7.         steps = 7 * (i + 1)
  8.     i = i + 1
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-29 04:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表