python - 给定范围内所有数字的总和除以 3 和 5,并将数字范围显示为列表
问题描述
def main(start,end):
range(start,end)
total=0
for nums in range(start,end):
if nums%3 ==0 or nums%5==0:
total=(total)+(nums)
return total
print(main(int(input("enter start ")),int(input("enter end "))))
如果我输入 1 到 100 答案将是 2318
如何在不重新输入的情况下打印数字范围列表?
print(list(range(start,end)))
例如我想要[1,2,3,4,...,99]
但没有输入但使用上面给出的原始输入
解决方案
这是帮助你
def main(start,end):
total=0
l = []
for nums in range(start,end):
l.append(nums)
if nums%3 ==0 or nums%5==0:
total=(total)+(nums)
print(l)
return total
print(main(int(input("enter start ")),int(input("enter end "))))
输出:
enter start 1
enter end 100
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99]
2318
推荐阅读
- python - 拟合模型 Ubuntu 18.04 时 Python Tensorflow GPU 错误
- polymer - 如何使用 mixin 为包含在 LitElement 自定义组件中的纸卡 (Polymer 3) 设置样式
- javascript - 如何在 1 页网站中使用 Javascript 或 jquery 进行页面更改
- amazon-web-services - Telnet works on AWS URL and localhost but not on IP
- keras - 如何设置 keras.layers.CuDNNLSTM 类的内核大小?
- node.js - 我可以在 MongoDB 的单个查询中更新不同的文档吗?
- z3 - 强制Z3先探索某个候选空间?
- python - 在函数中,我想用函数中的参数更新 mysql 表中的值
- javascript - 在 JavaScript 中同时分组和转换数据(使用 Lodash)
- html - 在 ASP.NET Core 中流式传输时如何设置持续时间视频?