我对python很陌生。我正在编写代码来生成一个数组的数组,但输出不是我想要的。输出不是我想要的
的代码如下
import numpy as np
n_zero=input('Insert the amount of 0: ')
n_one =input('Insert the amount of 1: ')
n_two =input('Insert the amount of 2: ')
n_three = input('Insert the amount of 3: ')
data = [0]*n_zero + [1]*n_one + [2]*n_two + [3]*n_three
np.random.shuffle(data)
print(data)
输出如下:
Insert the amount of 0: 10
Insert the amount of 1: 3
Insert the amount of 2: 3
Insert the amount of 3: 3
[0, 0, 3, 1, 0, 3, 2, 0, 3, 0, 2, 0, 2, 1, 1, 0, 0, 0, 0]
我想下面的输出:
0031032030202110000
谢谢
你有一个字符串列表。用'''.join(data)'将它转换为一个字符串。 – DyZ
'n_zero'是一个str。你不能用列表多列加一个str。尝试'int(n_zero)' – Lucas
print(''。join(map(str,data))) 我这样做,它的工作原理!谢谢! – jamarumori