<p>您的代码:</p>
<pre><code>while True:
try:
userInputOne = input(int("How much time in hours a week, do you spend practicing? ")
except TypeError:
print("Oops! Practice time must be rounded to the nearest integer. It also needs to be a numerical value! ")
break
else:
userInputTwo = str(input"How good to do want to be? Enter 'very good', 'good', mediocre, 'not good' ")
if userInputTwo not in ('very good', 'good', 'mediocre', 'not good'):
print("Please use one of the options. ")
else:
print("Let's calculate...")
break
</code></pre>
<p>首先,应该如下所示:</p>
<pre><code>while True:
try:
userInputOne = input(int("How much time in hours a week, do you spend practicing? "))
except TypeError:
...
...
</code></pre>
<p>我喜欢用一些方法来解决这个问题:</p>
<ul>
<li>对文件运行<a href="https://www.pylint.org/" rel="nofollow noreferrer">pylint</a>。它将告诉您哪里存在错误,并为您提供可以改进的代码警告</李>
<li>使用vim和命令<code>==</code>,它将尝试执行一些自动缩进</李>
</ul>
<p>但最重要的是要理解<a href="https://stackoverflow.com/questions/13884499/what-is-python-whitespace-and-how-does-it-work">whitespace is important in Python</a>。整个文件中都存在空格语法错误。代码中需要有四个空格而不是八个空格。另外,正如上面的注释所指出的,您有一些不平衡的括号,这将破坏您的代码。此外,还有一个<code>else</code>语句,没有<code>if</code>。周围有很多问题,所以我建议一次重新编写几行代码,并在继续之前确保它正常工作。此外,不能将字符串转换为int,否则至少会得到意外的结果</p>