简体   繁体   English

谁能告诉我这里的代码有什么问题?

[英]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.

相关问题 谁能告诉我我的功能出了什么问题? - Can anyone tell me what's wrong with my function? 有人可以告诉我我的 animation 代码有什么问题吗? - Can someone tell me what's wrong with my animation code? 谁能告诉我Python中的合并排序有什么问题吗? - Can anyone tell me what's wrong with my Merge Sort in Python? Python程序,谁能告诉我2在这里的含义是什么? - Python program, can anyone tell me what significance of the 2 is here? 您能告诉我代码有什么问题吗? - Could you tell me what's wrong with my code? 谁能告诉我我的 dequeue function 有什么问题,它不会在运行后从队列或 output 中删除任何内容 - Can anyone tell me what's wrong with my dequeue function, it wont remove anything from the queue or output after running it 谁能帮我找出问题所在? 我的代码中出现索引错误 - Can anyone help me find out what's wrong? Index error in my code 谁能告诉我快速排序代码中的错误是什么 - can anyone tell what's the bug in my quick sort code 有人能告诉我我的代码有什么问题吗 - Can someone tell me what is wrong with my code 任何人都可以告诉我为什么我的代码显示错误的pi值? - Can anyone tell me why is my code showing the wrong value of pi?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM