ALLCAPS ALLCAPS - 7 months ago 72
Python Question

List object not callable

I have an assignment to create a slot machine. I'm trying to write the loop that will spin the machine, but it keeps saying my list isn't callable.

Here's where I am having the issue:

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)
i += 1

I figured maybe the brackets were in the wrong space, but if I place them anywhere else I get a syntax error.


Update line with print(str[wheel1(spin1)]) to print(str(wheel1[spin1])).

The issue is when you do wheel1(), python treats that as function and try to call the function. But since you are having list and want to access the value, the syntax is wheel1[i] where i is the index you want to access.

Also, you are doing str[..], but instead it should be str(..) due to the same reason as mention above.