python - 我试图找出'n 到 m 以 p 为步长,其中 n、m 和 p 由用户输入'
解决方案
以下是您正在寻找的。
https://docs.python.org/3/tutorial/controlflow.html#for-statements https://docs.python.org/3/library/stdtypes.html#range
现在,您尝试编写的代码片段如下所示:
n = int(input("First Number: "))
m = int(input("Second Number: "))
p = int(input("Third Number: "))
# Start from n, go until m (includes m), in steps of p
for i in range(n, m + 1, p):
print(i, end = " ")
print()
推荐阅读
- c++ - 按字典升序对矩阵的行进行排序
- javascript - 如何使用方码方法创建秘密消息应用程序?
- node.js - 使用 UnauthorizedError 撤销 accessToken 不起作用
- javascript - 到处都支持 onreadystatechange 事件,但 document.readyState 不支持?
- java - javafx多线程如何顺序执行?
- python - 从列表列表生成迭代器列表
- maven - Jmeter with maven and using external groovy scripts issues with groovy imports
- android - How to use Fragments dynamically, within another Fragment
- c++ - Algorithm for converting Serial Date (Excel) to Year-Month-Day in C++
- html - Bootstrap 内容溢出移动导航栏宽度--学术会议网站