列表对象不是callab

2024-10-04 05:22:51 发布

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

我有个任务要做老虎机。我试着写一个循环来让机器旋转,但它一直说我的列表是不可调用的。你知道吗

我的问题是:

wheel1 = ['Candy','Ghost','Pumpkin','Cat','Zombie','Witch','Witch','Cat','Ghost','Candy']
wheel2 = ['Candy','Ghost','Pumpkin','Cat','Zombie','Witch','Cat','Pumpkin','Ghost','Candy']
wheel3 = ['Candy','Ghost','Pumpkin','Cat','Zombie','Witch','Pumpkin','Candy','Candy','Ghost']

#loop to spin
i = 0

while i < 500:
    spin1 = random.randint(0,9)
    spin2 = random.randint(0,9)
    spin3 = random.randint(0,9)
    print(str[wheel1(spin1)])
    i += 1

我想可能括号放错地方了,但如果我把它们放在其他地方,我会得到一个语法错误。你知道吗


Tags: 机器列表地方randomcatghostrandintzombie
1条回答
网友
1楼 · 发布于 2024-10-04 05:22:51

print(str[wheel1(spin1)])将行更新为print(str(wheel1[spin1]))。你知道吗

问题是,当您执行wheel1()时,python将其视为函数并尝试调用该函数。但是由于您有list并且想要访问该值,所以语法是wheel1[i],其中i是您想要访问的索引。你知道吗

另外,您正在执行str[..],但是由于与上面提到的相同的原因,它应该是str(..)。你知道吗

相关问题 更多 >