我有个任务要做老虎机。我试着写一个循环来让机器旋转,但它一直说我的列表是不可调用的。你知道吗
我的问题是:
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
我想可能括号放错地方了,但如果我把它们放在其他地方,我会得到一个语法错误。你知道吗
用
print(str[wheel1(spin1)])
将行更新为print(str(wheel1[spin1]))
。你知道吗问题是,当您执行
wheel1()
时,python将其视为函数并尝试调用该函数。但是由于您有list
并且想要访问该值,所以语法是wheel1[i]
,其中i
是您想要访问的索引。你知道吗另外,您正在执行
str[..]
,但是由于与上面提到的相同的原因,它应该是str(..)
。你知道吗相关问题 更多 >
编程相关推荐