为什么我的代码结果“module”对象不可订阅?

2024-09-27 17:36:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我想更改python时出错随机抽样数组索引。我想换我的随机抽样增加+1数组索引

x=0
randomarray = random.sample(range(1, len(codelist) - len(Genx1) - len(Genx2)), 3*len(s))

while (x < len(s)):
    randomarray.sort()
    print(randomarray)
    if ((codelist[randomarray[x]]=='B' ) and (s[x]=='A') or (codelist[randomarray[x]]=='A' ) and (s[x]=='B')):
        codelist[randomarray[x]] = s[x]
        x = x + 1
    else:
        random[x]= random[x]+1
        x = x

line 403, in ... random[x]= random[x]+1 TypeError: 'module' object is not subscriptable


Tags: orandsamplelenifrangerandom数组
1条回答
网友
1楼 · 发布于 2024-09-27 17:36:16

random是包含所有随机函数的模块的名称。您试图将其用作列表或数组:

random[x] = random[x] + 1

random[x]不是一个有意义的表达式。而且,x = x是一行无用的代码,它什么也不做。在

相关问题 更多 >

    热门问题