擅长:python、mysql、java
<p>在第一个<code>for</code>循环中,从<code>0</code>迭代到<code>len(s)-1</code>,但是您正在寻址{<cd4>},在最后一次迭代中,它是<code>len(s)</code>。在</p>
<p><code>s[len(s)]</code>是一个索引器——它超出了界限。在</p>
<hr/>
<p>另外,您的<code>while</code>循环将被关闭一个。在</p>
<pre><code>while i!= " " and i<=len(s):
# do something referencing s[i]
</code></pre>
<p>你的第一个条件没有意义(<code>i</code>是一个数字,怎么可能是<code>" "</code>?)你的第二个错误与上述相同,其中<code>i</code>最大值为<code>len(s)</code>,而{<cd6>}是一个错误。在</p>
<hr/>
<p>您的逻辑在这里也有点偏离,因为您将它包装在<code>for</code>循环中,该循环已经在引用<code>i</code>。这看起来是一个<code>takewhile</code>循环,但实际上并不是这样。在</p>