首页 > 解决方案 > 我试图找出'n 到 m 以 p 为步长,其中 n、m 和 p 由用户输入'

问题描述

我是编码新手,正在尝试弄清楚如何做到这一点,到目前为止我已经做到了:

到目前为止我编码的图像

谁能告诉我我需要做什么才能实现这一目标?

标签: python

解决方案


以下是您正在寻找的。

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()

推荐阅读