<p>在<code>while</code>循环中,<code>elif</code>后面的<code>break</code>语句将始终执行,因此循环将只运行一次。为了避免这种情况,您可以简单地将<code>break</code>放在<code>elif</code>语句中;说到<code>break</code>,如果您希望在每次从输入中获取<code>"REpeat"</code>时重复该循环,那么您希望删除<code>if</code>语句中的<code>break</code>。此外,在您的代码中,输入被执行两次:第一次调用<code>input()</code>检查<code>if</code>条件,另一次检查<code>elif</code>条件。为了避免这种情况,循环中要做的第一件事是将用户输入保存到变量中</p>
<p>此外,要小心,因为每个周期(当输入<code>"REpeat"</code>)调用<code>print()</code>函数两次,并将其返回值赋给<code>tell_joke</code>,然后再次调用<code>print()</code>函数来打印<code>tell_joke</code>变量,该变量包含<code>print()</code>的结果,这解释了“偶然的”<code>None</code>输出。为了防止多个无用的赋值,如果您不打算更改<code>tell_joke</code>的值,可以在整个循环之前,在<code>quit_game</code>字符串旁边声明并赋值。请记住,更清楚的是,仅使用这两个<code>if</code>语句,除了<code>"REpeat"</code>和<code>"Quit"</code>之外,您没有处理来自用户的任何其他输入,循环将只是重复本身</p>
<p>如果我正确理解您想要的输出,它应该是这样的:</p>
<pre class="lang-py prettyprint-override"><code>quit_game = "Goodbye, thank you for playing."
tell_joke = "Pete, Pete and Repeat went out on the lake in their boat. Pete and Pete fell out. Who is left in the boat?"
while True:
my_input = input()
if my_input == "REpeat":
print(tell_joke)
elif my_input == "Quit":
print(quit_game)
break
</code></pre>
<p>如果您想更多地了解python中的控制流工具,我将您重定向到它们的<a href="https://docs.python.org/3/tutorial/controlflow.html" rel="nofollow noreferrer">documentation</a></p>