好吧,我做了这个代码:
lst1 = tuple(range(1, 13))
table1 = ""
x = 0
while x < len(lst1):
for y in range(0, 3):
table1 += str(lst1[x]) + "\t"
x += 1
table1 += "\n"
print(table1)
#Output in console is:
1 2 3
4 5 6
7 8 9
10 11 12
我想再做两个表来显示其他的随机数,比如说:从0到48,但仍然只有12个从这个范围的数字会以这种格式输出。我对python相当陌生,似乎无法通过random模块理解它
这是随机数列表之一:
lst3 = tuple(range(0, 48))
table3 = ""
x = 0
while x < len(lst3):
for y in range(0, 3):
table3 += str(lst3[x]) + "\t"
x += 1
table3 += "\n"
print(random.sample(lst3, 12))
#Output is: (so basically just 12 random numbers from 1 to 47 that don't repeat)
[28, 15, 35, 11, 30, 20, 38, 3, 31, 42, 9, 24]
据我所知,你想要这样的东西:
相关问题 更多 >
编程相关推荐