擅长:python、mysql、java
<p>这是另一种方法。它使用列表理解并保留允许操作的列表。我也减少了法力来测试资源限制。你知道吗</p>
<pre><code>action_list = [['Wrath of Mordor', 25, 20, 70],
['Howl of the Ring Wraiths', 35, 25, 60],
['Might of Morgoth', 40, 35, 45],
['Pass']]
mana = 30
act_choice = [action for action in action_list
if len(action) >= 2 and action[2] <= mana]
if act_choice:
for action in act_choice:
print(action[0], action[2])
else:
print("Pass")
</code></pre>
<p>输出:</p>
<pre><code>Wrath of Mordor 20
Howl of the Ring Wraiths 25
</code></pre>