擅长:python、mysql、java
<p>在循环外保留布尔标志。如果至少找到一个元素,则将其设置为true。如果标志没有改变-打印关于找不到大于5的元素的语句:</p>
<pre><code>list = [100, 2, 1, 3000]
found = False
for x in list:
if int(x) < 5:
print(x)
found = True
if found == False:
print("There are no elements in this list greater than 5")
</code></pre>