슬롯 머신을 생성 할 과제가 있습니다. 나는 기계를 회전시키는 루프를 작성하려고하지만 내 목록이 호출 가능하지 않다는 것을 계속 말합니다. 여기목록 객체를 호출 할 수 없습니다.
내가 문제를 겪고 어디 :
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
나는 어쩌면 괄호가 잘못된 공간에 있었다 생각,하지만 난 다른 곳을 배치하면 나는 구문 오류가 발생합니다.
'wheel1'은 목록이고 괄호 (연산자)를 사용하여 목록 요소에 액세스합니다. 따라서 'wheel1 (spin1)'대신'wheel1 [spin1]'이어야합니다. 'str'에 대한 호출은 괄호를 사용해야하므로 print 문은'print (str (wheel1 [spin1]))'이어야합니다. – UnholySheep