擅长:python、mysql、java
<p>最简单的解决方案是在循环开始之前在初始化一些变量:</p>
<pre><code>choice=''
#This means that choice is False now
while not choice:
choice=input("Enjoying the course? (y/n)")
if choice in ("yn")
#any set of instructions
else:
print("Sorry, I didn't catch that. Enter again: ")
choice=""
</code></pre>
<p>while条件语句的意思是,只要<em>choice</em>变量为false——没有任何值意味着<em>choice</em>='',则继续循环
如果<em>选项</em>有任何值,则继续进入循环体并检查
特定输入的值,如果输入不满足所需的值
然后再次将<em>选项</em>变量重置为False值以继续提示用户
直到提供正确的输入</p>