擅长:python、mysql、java
<p>我想你的问题是,一旦玩家选择了一个数字,你就不知道如何访问所选的卡。在</p>
<p>如果是这样的话,你已经接近解决方案了!在</p>
<p>当播放器输入一个数字时,您将它作为一个字符串存储在<code>pick</code>变量中。接下来的步骤是:</p>
<ol>
<li>将该字符串转换为整数,然后</li>
<li>在牌堆的那个位置找到牌。在</li>
</ol>
<p>Python有一个<a href="https://docs.python.org/3/library/functions.html#int" rel="nofollow noreferrer">built-in ^{<cd2>} function</a>,用于将pick从字符串转换为整数。在</p>
<p>您的<code>deck</code>变量是一个列表,要从Python中的列表中获取项,可以按索引请求该项。索引是表示该项位置的数字:</p>
<pre><code>animals = ["cat", "dog", "fish", "pterodactyl]
print(animals[0]) # "cat"
print(animals[1]) # "dog"
print(animals[2]) # "fish"
</code></pre>
<p>将此添加到代码中可以实现以下目的:</p>
^{pr2}$