擅长:python、mysql、java
<p>无论何时在python中使用<a href="https://docs.python.org/3/library/functions.html#input" rel="nofollow noreferrer">^{<cd1>}</a>函数,它都会返回一个字符串。引用文档(emphasis mine):</p>
<blockquote>
<p>The function then reads a line from input, <strong>converts it to a string</strong> (stripping a trailing newline), and returns that. </p>
</blockquote>
<p>从文档中可以看到,<code>input()</code>函数将输入转换为字符串并返回它。因此,您不能对它执行<code>+= 1</code>之类的操作,因为它是一个字符串。在</p>
<p>要将字符串转换为int,需要使用<code>int()</code>函数。因此,代码行将是:</p>
<pre><code>Exponet = int(input("Exponet: "))
</code></pre>
<p>这将修复您的问题,因为<code>int()</code>函数将字符串转换为int,然后您应该能够对它们执行<code>+=</code>之类的操作。在</p>
<hr/>
<p>旁注:<code>Exponet</code>是一个错误的拼写,它是<code>Exponent</code>(注意额外的<code>n</code>)。在</p>