-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