擅长:python、mysql、java
<p>如果某些名称匹配,内部循环应该使用标志集</p>
<pre><code>while True:
writerSurname = input("Pls enter the writer's surname.")
if writerSurname in ['exit', 'Exit']:
break
found = False
for k in books:
if writerSurname == k[3]:
found = True
print(k[1],'writer', k[2],k[3], "cost is", k[4],"TL")
if not found:
print(writerSurname, 'there is no such a person.')
break
</code></pre>
<p>请注意,对于单个中断匹配(此处不适用),可以使用<code>for/else</code>语句:</p>
<pre><code> for k in books:
if writerSurname == k[3]:
print(k[1],'writer', k[2],k[3], "cost is", k[4],"TL")
break
else:
# end of the loop reached, without break: enters here
print(writerSurname, 'there is no such a person.')
</code></pre>