![](/img/trans.png)
[英]Pygame Error getting list index out of range but i dont know how to fix (I'm new)
[英]i dont know why i get error list index out of range
def longest_run(L):
inc = []
num = 0
count = 0
index = 1
while count < len(L)+1:
if L[num] >= L[index]:
inc.append(L[index])
num +=1
index +=1
count += 1
print (inc)
L = [10, 4, 3, 8, 3, 4, 5, 7, 7, 2]
當拿我的代碼時,我得到一個錯誤
if L[num] > L[index]:
IndexError: list index out of range
我不知道為什么我的索引超出范圍,例如,如果num = 2則索引= 3不超出范圍,請幫助我
由於出現len(L)+1而導致錯誤
在print(inc)
之前添加print num, index, count
,您將解決它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.