>>> L = ['Bart', 'Lisa', 'Adam']
>>> n=-1
>>> while n<3:
n=n+1
print('Hello,'+L[n])
Hello,Bart
Hello,Lisa
Hello,Adam
Traceback (most recent call last):
File "<pyshell#75>", line 3, in <module>
IndexError: list index out of range
L 有效索引:0.1.2
while n < 3
n = 2 + 1 => 3
啊感谢感谢!发现错误了,改成n<2终于好了
没有这么复杂吧,你看我写这个
L = ['Bart', 'Lisa', 'Adam']
for a in L:
a = "HELLO" + "," + a + "!"
print(a)
Sign in to make a reply
你在干什么呀小怪怪
>>> L = ['Bart', 'Lisa', 'Adam']
>>> n=-1
>>> while n<3:
n=n+1
print('Hello,'+L[n])
Hello,Bart
Hello,Lisa
Hello,Adam
Traceback (most recent call last):
File "<pyshell#75>", line 3, in <module>
print('Hello,'+L[n])
IndexError: list index out of range