[英]Can anyone tell me what's wrong with my code here?
I have some code written here for a Codio challenge that I can't seem to figure out how to correctly write.我在这里为 Codio 挑战编写了一些代码,我似乎无法弄清楚如何正确编写。 I'm fairly new to Python and for some reason this times table loop challenge is killing me.
我对 Python 还很陌生,出于某种原因,这次表循环挑战让我很沮丧。 The code is as follows:
代码如下:
# Get N from the command line
import sys
N = int(sys.argv[1])
for i in range(1, 13):
N = N + i
print(str(N))
The question asks:问题问:
We will provide you with a number N. Output the times table for that number from 1 to 12.我们将为您提供一个数字 N。输出该数字从 1 到 12 的时间表。
So, if we pass in 6, you should output 6, 12, 18, 24 … 66, 72所以,如果我们传入 6,你应该输出 6, 12, 18, 24 ... 66, 72
Any help would be greatly appreciated.任何帮助将不胜感激。
Just use index * N只需使用索引 * N
In [11]: N = 6
In [12]: for i in range(1, 13):
...: print(N*i)
...:
...:
...:
6
12
18
24
30
36
42
48
54
60
66
72
In [13]:
You are adding the loop index to the number N
, you need to multiply instead.您将循环索引添加到数字
N
,您需要进行乘法运算。
for i in range(1, 13):
print(N*i)
for i in range(1, 13):对于范围内的 i (1, 13):
print(N*i)打印(N*i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.