<p>给出一个数字列表,说:</p>
<pre><code>[0,0,2,4]
</code></pre>
<p>我需要提示用户在最小值和最大值之间选择一个数字。你知道吗</p>
<p>例如,我想提示用户:</p>
<pre><code>"Enter a number between 0 and 4: "
</code></pre>
<p>并让用户输入该范围内的数字。为此,我需要计算列表的最小值和最大值。你知道吗</p>
<p>因此,如果列表是<code>[1,2,4,6,7]</code>,则提示应更改为:</p>
<pre><code>"Enter a number between 1 and 7: "
</code></pre>
<p>我试过这个:</p>
<pre><code>input("Enter a number from {0} and {1}: ").format(min(lst),max(lst))
</code></pre>
<p>…但是这不起作用。有人能帮忙吗?你知道吗</p>
<p>你的<code>.format</code>必须在<code>input()</code>的括号内。您正在尝试<code>format</code>该函数的结果,而不是字符串。你知道吗</p>
<pre><code>input("Enter a number from {0} and {1}: ".format(min(lst),max(lst)))
^ Parenthesis moved from here
</code></pre>