[英]Python List Indexing Issue
Please Tell me what's going wrong in my codes, it's showing "d[j+1]=int(n) Index Error: list assignment index out of range"... see that line 13请告诉我我的代码出了什么问题,它显示“d[j+1]=int(n) Index Error: list assignment index out of range”...见第 13 行
d
only has one value, which is 10
. d
只有一个值,即10
。 You are trying to take the index 0+1
, ie the second element in d
, even though this second element doesn't exist.您正在尝试获取索引
0+1
,即d
中的第二个元素,即使该第二个元素不存在。
Perhaps d.append(j)
is what you're looking for?也许
d.append(j)
是你在找什么?
If I understood correctly what you want, it would have to be like this:如果我正确理解你想要什么,它必须是这样的:
b=3
print(b)
d=[0]
a=[5]
i=0
j=0
c=0
while(c<d[0]):
print("Enter Values: ")
m,n=(input(" ").split(','))
d[j]=int(m)
m=0
d[j+1]=int(n)
n=0
a[i]=d[j]+d[j+1]
a[i+1]
print("Answer: "+ str(a))
Result:结果:
3
Answer: [5]
Since c and d are equal to 0 , while passes through and prints the a由于c和d等于0 ,而通过并打印 a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.