-1
我在Python代碼的一點經驗,我試着寫總結在列表中的項目,除了數字99碼這是我的代碼:While循環澄清python-錯誤
grade = [100,30,99,85]
i = 0
while grade[i]!=99:
i = i + grade[i]
print i
但我得到這個錯誤:
>>>
100
Traceback (most recent call last):
File "G:\desktop\test.py", line 3, in <module>
while grade[i]!=99:
IndexError: list index out of range
>>>
請解釋一下你的第二個音符 – newGIS
@newGIS增加了一個解釋。 – DeepSpace
那麼,我怎麼能在我的代碼中做到這一點,而不是使用sum函數? – newGIS