我已經編程了大約1周。列表索引超出範圍,但我重置索引(Python)
我正在寫一個簡單的程序來循環這個List並每次將變量加1。
我得到錯誤:列表索引超出範圍。
我相信這是因爲我的指數值太高? 而且走得太高之前,我重新索引值:
index += 1
index and 7
的邏輯,一旦它成爲> = 8應該重置指數爲0,不應該嗎?
在這種情況下,我不明白什麼是錯的。請參閱我的代碼:
lookups = [0,1,2,3,4,5,6,7]
index = 0
dword_C06748 = 0
count = 0
offset1 = 0
rn_offset = 0
def next_value():
global lookups, index, count
while count < 18:
lookups[index] += 1
index += 1
index and 7
count += 1
next_value()
你覺得呢'指數和7'呢? – tacaswell
'index = index%8'對我來說似乎更符合邏輯。 – Aleph
@tcaswell我認爲它執行一個邏輯與使用變量'索引'與7.因此,當索引= 8時,它將做8和7.答案是0,應該指定0索引。 – BBedit