擅长:python、mysql、java
<p>问题出在18号线</p>
<pre><code>s = []
s.insert(0,str("a b c"))
s.insert(1,str("a b c d"))
s.insert(2,str("a b"))
s.insert(3,str("b c"))
s.insert(4,str("d"))
print(s)
j = 0
i = 0
while j < 5:
if s[j] in s[i]:
print("\"" + s[j] + "\" is in the string \"" + s[i] + "\"")
i +=1
if i == 5 and j < 4: <-- here
j+=1
i=0
</code></pre>
<p>在某个时刻,您的<code>i = 5</code>和<code>j = 4</code>,因此<code>if i == 5 and j < 4</code>语句的右侧为False,<code>i</code>不会重置为0。所以在下一个循环中,<code>i</code>等于5,最大索引是4。在</p>
<p>更好的解决方案是使用for循环。在</p>
^{pr2}$
<h2>编辑以答复评论</h2>
^{3}$