[英]Python: The range function is only printing one number in a multidimensional list
import random
cardGrid = [[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,1,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]]
for i in range(7):
for x in range (1, 51):
if x % 13 != 0:
cardGrid[0][i] = x
cardGrid[1][i] = x
cardGrid[2][i] = x
cardGrid[3][i] = x
cardGrid[4][i] = x
cardGrid[5][i] = x
cardGrid[6][i] = x
print(cardGrid)
The aim of this code is too input a range of numbers "x", that is not divisible by 13, into the multi-dimensional list.这段代码的目的是将不能被 13 整除的数字“x”的范围输入到多维列表中。
This is the result I got这是我得到的结果
It only prints one number consistently, throughout the array.它只在整个数组中一致地打印一个数字。 For those who can not use the link it looks like this:
对于那些无法使用链接的人,它看起来像这样:
[[51,51,51,51,51,51,51],[51,51,51,51,51,51,51],[51,51,51,51,51,51,51],[51,51,51,51,51,51,51],[51,51,51,51,51,51,51],[51,51,51,51,51,51,51],[51,51,51,51,51,51,51]]
The range "i" function works, its the range for "x" that I am having problems with.范围“i”function 有效,我遇到问题的“x”范围。 Just a heads up, I'm new to coding in general, don't know if the way I put my question before hurt anyone, because I'm already getting disliked bombed.
提醒一下,我一般是编码新手,不知道我提出问题的方式是否会伤害任何人,因为我已经不喜欢被轰炸了。
I did not get what the main question is.我不明白主要问题是什么。 This is the answer to the below part.
这是下面部分的答案。
The aim of this code is too input a range of numbers "x", that is not divisible by 13, into the multi-dimensional list:
这段代码的目的是将不能被 13 整除的数字“x”的范围输入到多维列表中:
cardGrid = [[],[],[],[],[],[],[]]
for i in range(7):
for x in range (1, 15):
if x % 13 != 0:
cardGrid[i].append(x)
print(cardGrid)
[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.