opponent = [1, 1, 1, 1, 1, 1]
我只想要第一個元素在我的名單「對手」,所以我再代碼:IndexError但我不知道什麼是錯
opponent = int(opponent[0])
我用它來再算上數量'對手的在我的其他名單之一。
if wongames.count(opponent) == 2:
...blablabla
它說我提交的 行提出型IndexError的異常。 'opponent = int(opponent [0])')。
這是爲什麼?我該如何解決? :(
你的問題不清楚。你應該發佈你的代碼。你爲什麼要在這裏給int賦一個int? INT(oppponent [0])。 – Wiredo
將變量名稱改爲「對手」。您在步驟'opponent = int(opponent [0])''中將對手列表重新聲明爲整數。所以你不能把它用作列表。 – lpsandaruwan