答案:

代码如下:

res = []
for i in range(20, 1000):
    if i % 2 != 0:
        if (i**3) % 2 == 0:
            res.append(i)

with open('res.txt', 'w') as f:
    for i in res:
        f.write(str(i) + '\n')

结果输出到res.txt文件中。

求20~999满足以下条件的数:1、该数为奇数2、该数的立方和为偶数3 并将结果输公在restxt中

原文地址: https://www.cveoy.top/t/topic/husg 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录