英文:
Printing values in steps
问题
我正在按1的步长打印数值,但我想按10的步长打印。
总数 = 11
for t in range(0, 总数, 10):
print(t)
当前输出是
0
10
预期输出是
0
10
英文:
I am printing values in steps of 1, but I want to print in steps of 10.
Total = 11
for t in range(0, Total):
print(t)
The current output is
0
1
2
3
4
5
6
7
8
9
10
The expected output is
0
10
答案1
得分: 1
只需简单使用 range()
函数的 step
参数:
for t in range(0, Total, 10):
对于正步长,范围
r
的内容由公式r[i] = start + step*i
确定,其中i >= 0
且r[i] < stop
。对于负步长,范围的内容仍然由公式
r[i] = start + step*i
确定,但约束条件是i >= 0
且r[i] > stop
。
英文:
Simply use the step
argument of the range()
function:
for t in range(0, Total, 10):
> For a positive step, the contents of a range r
are determined by the formula r[i] = start + step*i
where i >= 0
and r[i] < stop
.
>
> For a negative step, the contents of the range are still determined by the formula r[i] = start + step*i
, but the constraints are i >= 0
and r[i] > stop
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论