每當我運行程序時,它要麼錯誤移動一個字符串從一個列表到另一個
Traceback (most recent call last):
File "C:\Users\mrosales\Downloads\Rock Paper Sissor Tornament.py", line 46, in <module>
Temp = ClassList[Random2]
IndexError: list index out of range
Traceback (most recent call last):
File "C:\Users\mrosales\Downloads\Rock Paper Sissor Tornament.py", line 60, in <module>
Temp = ClassList[Random2]
IndexError: list index out of range
我的代碼是關於從一個列表移動串到另一個形成tornamnet的一套遊戲大作
import random
import time
Temp = (" ")
ClassList = ['Noah','Simone','Ji Ho','Thanh','Nathanial','Soo','Mickel','Tuan']
Match1 = [], Match2 = [], Match3 = [] ,Match4 = []
Random1 = random.randrange(0,len(ClassList))
Random2 = random.randrange(0,len(ClassList))
while Random1 == Random2:
Random1 = random.randrange(0,len(ClassList))
time.sleep(1)
Temp = ClassList[Random1]
Match1.append(Temp)
del ClassList[Random1]
Temp = ClassList[Random2]
del ClassList[Random2]
Match1.append(Temp)
print(Match1)
Random1 = random.randrange(0,len(ClassList))
Random2 = random.randrange(0,len(ClassList))
while Random1 == Random2:
Random1 = random.randrange(0,len(ClassList))
time.sleep(1)
Temp = ClassList[Random1]
Match2.append(Temp)
del ClassList[Random1]
Temp = ClassList[Random2]
del ClassList[Random2]
Match2.append(Temp)
print(Match2)
Random1 = random.randrange(0,len(ClassList))
Random2 = random.randrange(0,len(ClassList))
while Random1 == Random2:
Random1 = random.randrange(0,len(ClassList))
time.sleep(1)
Temp = ClassList[Random1]
Match3.append(Temp)
del ClassList[Random1]
Temp = ClassList[Random2]
del ClassList[Random2]
Match3.append(Temp)
print(Match3)
Random1 = random.randrange(0,len(ClassList))
Random2 = random.randrange(0,len(ClassList))
while Random1 == Random2:
Random1 = random.randrange(0,len(ClassList))
time.sleep(1)
Temp = ClassList[Random1]
Match4.append(Temp)
del ClassList[Random1]
Temp = ClassList[Random2]
del ClassList[Random2]
Match4.append(Temp)
print(Match4)
Random1 = random.randrange(0,len(ClassList))
Random2 = random.randrange(0,len(ClassList))
while Random1 == Random2:
Random1 = random.randrange(0,len(ClassList))
print ("The current match ups are...")
print (Temp)
time.sleep(1)
print (Match1, Match2, Match3, Match4)
任何人能發現我可能已經放置,如果他們願意的話,糾正錯誤?
發佈完整的追溯?哪一行導致錯誤? – ZdaR
你有沒有試過把一些突破點和步進?你可能會找到問題所在。 –
@ZdaR它的一種長碼,如果我編輯我的文章並輸入完整的代碼,它會填充多於屏幕頁面...你確定嗎?我不介意只要你確認 –