擅长:python、mysql、java
<pre><code>result = {}
question = "What is your name"
question_2 = "If you could go to any place in the world for vacation, where would you like to go?"
question_3 = "Would you like to let people next to you participate in this survey?"
while True:
name = input(question)
place = input(question_2)
result[name] = place #除了yes或者no不允许输入其他字符
while True: #No other characters are allowed except "yes" or "no"
opinion = input(question_3)
if opinion.lower() not in ('yes','no'):
print('please enter again')
else:
break
if opinion == 'no':
break
</code></pre>
<p>你可以用一个元组来解决你的问题,这是第一件事</p>
<p>现在您想知道的是为什么以下代码不起作用:</p>
<pre><code>x != "yes" or "no"
</code></pre>
<p>按照优先顺序回忆一下!=具有比或更高的优先级,因此x!=首先计算“是”,然后用“否”对其进行or运算,为了解决这个问题,在or语句周围添加括号:</p>
<pre><code>x != ("yes" or "no")
</code></pre>
<p>我会帮你的</p>